-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Selection on term defined in current clause unexpectedly fails #17242
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
Comments
Following today's investigation, here is what I found: Note that |
I added the tests in the PR above |
Yup, Complete stack trace
|
#17256 demonstrates that the problem is indeed the nested reading of I am wondering what other approaches we could take to solve this problem. Seems like we should generally avoid |
Another possibility could be to disable the check in diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
index 98e9cb638c1..8f3a18f38f3 100644
--- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
+++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
@@ -289,6 +289,10 @@ trait TypeAssigner {
else fntpe.resultType // fast path optimization
else
errorType(em"wrong number of arguments at ${ctx.phase.prev} for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.srcPos)
+ case NoType if fn.tpe.isInstanceOf[TermRef] =>
+ // TermRef is not bound yet. Wait silently.
+ // See https://github.com/lampepfl/dotty/issues/17242.
+ fn.tpe
case t =>
if (ctx.settings.Ydebug.value) new FatalError("").printStackTrace()
errorType(err.takesNoParamsMsg(fn, ""), tree.srcPos) But this is probably too general (makes |
This compiles: class local(predicate: Int) extends annotation.StaticAnnotation
def working4(x: Int, y: Int @local((() => x + x)())) = () |
This might be related to the following: def foo[A, B](x: A, y: B = x) = () //error: not found: x
def bar[A, B](x: A)(y: B = x) = () (This also showcases why it's useful that default parameters are checked at call-site) |
Compiler version
Scala 3.2.2
Minimized code and Ouptut
Scastie which also contains the examples below:
https://scastie.scala-lang.org/jfNlEM8sR26DI2priR6mWQ
Expectation
Assuming following definitions in scope
The above should compile since the reference to x is totally valid here, for example the following compiles:
You can see in particular that it is the selection that causes the problem, and not the reference to
x
In dependent types, the selection doesn't cause the same problem:
Notice that the error mentions
Int
explicitly, so it has to knowx.length
is both a valid selection, and of typeInt
I do not advocate for changing the following however:
Finally, here is another failing example, even though the selection in question is
==
which is defined on (pretty much?) every Scala type:The text was updated successfully, but these errors were encountered: