Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use previous type of Apply.fun when copying if none available #21884

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
case tree: Apply
if (fun.tpe eq tree.fun.tpe) && sameTypes(args, tree.args) =>
tree1.withTypeUnchecked(tree.tpe)
case tree: Apply if fun.tpe.underlyingIfProxy == NoType =>
// The function type is not yet known. This happens for example if its
// type refers to a previous parameter in the same parameters list. In
// this case, we use the previously known type of the function.
// See tests/pos/dependent-annot-2.scala for an example.
ta.assignType(tree1, fun.withType(tree.fun.tpe), args)
case _ => ta.assignType(tree1, fun, args)
}
}
Expand Down
30 changes: 30 additions & 0 deletions tests/pos/dependent-annot-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class dummy(b: Any) extends annotation.StaticAnnotation

class X:
def foo() = 1
def bar() = 2
def eq(x: X) = true
def id(): this.type = this

class Y extends X:
override def bar() = 2
override def eq(x: X) = true

def f(x: Int) = x
def g(x: String) = x
def g(x: Int) = x

object AnnotationTests:
def foo1(elem: Int, bla: Int @dummy(Array(elem))) = bla
def foo2(elem: X, bla: Int @dummy(elem.foo())) = bla
def foo3(elem: Y, bla: Int @dummy(elem.foo())) = bla
def foo4(elem: X, bla: Int @dummy(elem.bar())) = bla
def foo5(elem: Y, bla: Int @dummy(elem.bar())) = bla
def foo6(elem: X, bla: Int @dummy(elem.eq(X()))) = bla
def foo7(elem: Y, bla: Int @dummy(elem.eq(Y()))) = bla
def foo8(elem: X, bla: Int @dummy(elem.id().foo())) = bla
def foo9(elem: Y, bla: Int @dummy(elem.id().foo())) = bla
def foo10(elem: Int, bla: Int @dummy(f(elem))) = bla
def foo11(elem: Int, bla: Int @dummy(g(elem))) = bla
def foo12(elem: Int, bla: Int @dummy(0 == elem)) = bla
def foo13(elem: Int, bla: Int @dummy(elem == 0)) = bla
Loading