Skip to content

Commit 5ff2e89

Browse files
committed
Reject structural applications of polymorphic methods
Fixes #15065 We always intended to reject them, but crashed before we got to that point.
1 parent b1f00a7 commit 5ff2e89

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,12 +578,12 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
578578
pre
579579
case _ =>
580580
tree1
581-
581+
582582
val countsAsPure =
583583
if dropOp(tree1).symbol.isInlineVal
584584
then isIdempotentExpr(tree1)
585585
else isPureExpr(tree1)
586-
586+
587587
if countsAsPure then Literal(value).withSpan(tree.span)
588588
else
589589
val pre = dropOp(tree1)
@@ -879,14 +879,15 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
879879
}
880880
!tree.symbol.exists && tree.isTerm && hasRefinement(tree.qualifier.tpe)
881881
}
882-
def loop(tree: Tree): Boolean = tree match {
882+
def loop(tree: Tree): Boolean = tree match
883+
case TypeApply(fun, _) =>
884+
loop(fun)
883885
case Apply(fun, _) =>
884886
loop(fun)
885887
case tree: Select =>
886888
isStructuralTermSelect(tree)
887889
case _ =>
888890
false
889-
}
890891
loop(tree)
891892
}
892893

tests/pos/i15065.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Foo extends reflect.Selectable
2+
3+
val foo = new Foo:
4+
def bar[A](): Int = ???
5+
6+
val x = foo.bar() // error: Structural access not allowed on method bar because it is polymorphic
7+
8+
val y = foo.bar[Int]() // error: Structural access not allowed on method bar because it is polymorphic

0 commit comments

Comments
 (0)