-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix:better error msg for cyclic error for constructors #17131
base: main
Are you sure you want to change the base?
Conversation
@doofin can we have a test case for this, at least? |
ok,I'll try to look at tests and find a suitable place to add them |
@dwijnand added one test case |
@@ -140,8 +140,11 @@ class CyclicReference private (val denot: SymDenotation)(using Context) extends | |||
// cycleSym.flags would try completing denot and would fail, but here we can use flagsUNSAFE to detect flags | |||
// set by the parser. | |||
val unsafeFlags = cycleSym.flagsUNSAFE | |||
val isMethod = unsafeFlags.is(Method) | |||
val isMethod = unsafeFlags.is(Method) // sometimes,isMethod and isConstructor can both be true! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that a symbol can both be isMethod and isConstructor ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It is a method because it is represented with a def
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if I remember correctly, isMethod is true(which shouldn't be) for case class as in #17076 so I add this warning, maybe I should indicate in a different way? (or maybe open a different issue for isMethod)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we print in PostTyper
case tree: DefDef =>
println("---")
println("DefDef: " + tree.show)
println("flags: " + tree.symbol.flagsString)
println("isConstructor: " + tree.symbol.isConstructor)
we can see that this class
class F(a: Int):
def this() = this(0)
def f = 1
has the the Method
flag and isConstructor
to true
for both the primary and secondary constructors.
---
DefDef: def <init>(a: Int): Unit
flags: <method> <stable> <touched>
isConstructor: true
---
DefDef: def <init>(): Unit =
{
this(0)
()
}
flags: <method> <touched> <no-default-params>
isConstructor: true
---
DefDef: def f: Int = 1
flags: <method> <touched>
isConstructor: false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What might happen is that the Method
was not in flagsUNSAFE
because it would be computed and added to flags
while typing. But the failure may have happened before that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks i got it, removed the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message of the failing code is
-- Error: t/Test.scala:7:30 ----------------------------------------------------
7 | case class Foo[T <: Int](x: Any)
| ^^^
| Something's wrong: missing original symbol for type tree
-- [E044] Cyclic Error: t/Test.scala:7:2 ---------------------------------------
7 | case class Foo[T <: Int](x: Any)
| ^
| Overloaded or recursive constructor Foo needs return type
|
| Run with -explain-cyclic for more details.
|
| longer explanation available when compiling with `-explain`
We should fix the Something's wrong: missing original symbol for type tree
. Patching the second error is not going to help. It might even hide useful information such as the info of -explain-cyclic
that tells us how this happened.
@nicolasstucki could you point out which file/LOC that I should change? |
Not sure where the bug that ended up with But it does not seem like something simple to figure out. The message was added in 9c834fc. Which comes from a The issue might be located in |
This provides better error msg for #17076 , doesn't solve the cyclic error yet