Skip to content

Commit 2c33887

Browse files
committed
Sharpen structural apply test to exclude PolyFunction applies
1 parent 5ff2e89 commit 2c33887

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,9 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
877877
case _ =>
878878
false
879879
}
880-
!tree.symbol.exists && tree.isTerm && hasRefinement(tree.qualifier.tpe)
880+
!tree.symbol.exists
881+
&& !tree.qualifier.tpe.widen.derivesFrom(defn.PolyFunctionClass)
882+
&& tree.isTerm && hasRefinement(tree.qualifier.tpe)
881883
}
882884
def loop(tree: Tree): Boolean = tree match
883885
case TypeApply(fun, _) =>

tests/neg-custom-args/fatal-warnings/structural.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object RClose {
4040
package p3 {
4141

4242
object Test {
43-
def idMap[C[_],T](m: { def map[U](f: T => U): C[U] }): C[T] = m.map(t => t) // error: polymorphic refinement method map without matching type in parent Object is no longer allowed
43+
def idMap[C[_],T](m: { def map[U](f: T => U): C[U] }): C[T] = m.map(t => t) // error: polymorphic refinement method map without matching type in parent Object is no longer allowed // error: Structural access not allowed
4444

4545
def main(args: Array[String]): Unit = {
4646
idMap(Some(5)) // error: type mismatch: found Some[Int], required Object{map: [U](f: Any => U): Any}
File renamed without changes.

tests/neg/structural.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Test3 {
66
val y: { type T = Int; def t = 4; def f(a:T) = true } // error: illegal refinement // error: illegal refinement
77
= new { type T = Int; def t = 4; def f(a:T) = true }
88

9-
def h(x: { def f[T](a: T): Int }) = x.f[Int](4) // error: polymorphic refinement method ... no longer allowed
9+
def h(x: { def f[T](a: T): Int }) = x.f[Int](4) // error: polymorphic refinement method ... no longer allowed // error: Structural access not allowed
1010

1111
type A = { def foo(x: Int): Unit; def foo(x: String): Unit } // error: overloaded definition // error: overloaded definition
1212
type B = { val foo: Int; def foo: Int } // error: duplicate foo

0 commit comments

Comments
 (0)