Skip to content

Commit e0edb2f

Browse files
committed
Use previous type of Apply.fun when copying if none available
1 parent b47f0f2 commit e0edb2f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
661661
case tree: Apply
662662
if (fun.tpe eq tree.fun.tpe) && sameTypes(args, tree.args) =>
663663
tree1.withTypeUnchecked(tree.tpe)
664+
case tree: Apply if fun.tpe.underlyingIfProxy == NoType =>
665+
// The function type is not yet known. This happens for example if its
666+
// type refers to a previous parameter in the same parameters list. In
667+
// this case, we use the previously known type of the function.
668+
// See tests/pos/dependent-annot-2.scala for an example.
669+
ta.assignType(tree1, fun.withType(tree.fun.tpe), args)
664670
case _ => ta.assignType(tree1, fun, args)
665671
}
666672
}

tests/pos/dependent-annot-2.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class dummy(b: Any) extends annotation.StaticAnnotation
2+
3+
class X:
4+
def foo() = 1
5+
def bar() = 2
6+
def eq(x: X) = true
7+
def id(): this.type = this
8+
9+
class Y extends X:
10+
override def bar() = 2
11+
override def eq(x: X) = true
12+
13+
def f(x: Int) = x
14+
def g(x: String) = x
15+
def g(x: Int) = x
16+
17+
object AnnotationTests:
18+
def foo1(elem: Int, bla: Int @dummy(Array(elem))) = bla
19+
def foo2(elem: X, bla: Int @dummy(elem.foo())) = bla
20+
def foo3(elem: Y, bla: Int @dummy(elem.foo())) = bla
21+
def foo4(elem: X, bla: Int @dummy(elem.bar())) = bla
22+
def foo5(elem: Y, bla: Int @dummy(elem.bar())) = bla
23+
def foo6(elem: X, bla: Int @dummy(elem.eq(X()))) = bla
24+
def foo7(elem: Y, bla: Int @dummy(elem.eq(Y()))) = bla
25+
def foo8(elem: X, bla: Int @dummy(elem.id().foo())) = bla
26+
def foo9(elem: Y, bla: Int @dummy(elem.id().foo())) = bla
27+
def foo10(elem: Int, bla: Int @dummy(f(elem))) = bla
28+
def foo11(elem: Int, bla: Int @dummy(g(elem))) = bla
29+
def foo12(elem: Int, bla: Int @dummy(0 == elem)) = bla
30+
def foo13(elem: Int, bla: Int @dummy(elem == 0)) = bla

0 commit comments

Comments
 (0)