-
Notifications
You must be signed in to change notification settings - Fork 1.1k
REPL - fix collective extensions #13375
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
Conversation
statSepOrEnd(meths, what = "extension method") | ||
val m = extMethodOpt(numLeadParams) | ||
m.foreach(meths += _) | ||
m.isDefined && statSepOrEnd(meths, what = "extension method") |
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.
m.isDefined && statSepOrEnd(meths, what = "extension method") | |
if !m.isDefined then syntaxErrorOrIncomplete("`def` expected") | |
statSepOrEnd(meths, what = "extension method") |
I think this may fix the failure in tests/neg/extension-methods.scala
Or maybe a bit cleaner as
extMethodOpt(numLeadParams) match
case Some(m) => meths += m
case None => syntaxErrorOrIncomplete("`def` expected")
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 for help! I played with your suggestion and found even more compact way to fix this problem
I was going to help out, but it's too bad dotty testing is more complicated than scala 2 partest/junit. Every test is a research project. Locally,
|
aa3fd86
to
6e34f77
Compare
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.
Some thoughts on the current implementation:
scala> extension (x: Int) { ; def foo = 42 }
def foo(x: Int): Int
The above is now accepted, but I believe it should be disallowed by the grammar (before this PR it gives an error on the ;
character)
Also, a little more subjective:
file.scala
extension (x: Int)
private val foo = 10
def bar = foo
With this PR:
$ ./bin/scalac file.scala
-- Error: file.scala:2:10 ----------------------------------------------
2 | private val foo = 10
| ^^^
| end of extension method expected but 'val' found
-- [E040] Syntax Error: file.scala:4:0 ---------------------------------
4 |
|^
|eof expected, but unindent found
-- [E006] Not Found Error: file.scala:3:12 -----------------------------
3 | def bar = foo
| ^^^
| Not found: foo
Previously:
$ scalac file.scala
-- [E040] Syntax Error: file.scala:2:10 ----------------------------------------
2 | private val foo = 10
| ^^^
| 'def' expected, but 'val' found
-- [E006] Not Found Error: file.scala:3:12 -------------------------------------
3 | def bar = foo
| ^^^
| Not found: foo
In this case, the existing error messages seem clearer to me than those with this PR.
I was suspicious of https://github.com/lampepfl/dotty/compare/master...som-snytt:dos65/repl-latest?expand=1 I wasted some time comparing trees because I didn't realize extensions had changed recently. So I won't push it further. The gist is that This version preserves the edge behavior mentioned above. |
@griggt oops! That for pointing at this, will look how to fix that. |
That is, my branch preserves the messaging mentioned by @griggt . |
@som-snytt Oh, I've just took a look at your changes - your version is better especially because of introducing |
@dos65 I suspect the new empty tree does not pull its weight; it's basically just to signal from The Feel free to steal whatever is useful, or if you are bored with it, I can make another pass and PR. |
Actually I have a few minutes where I can either PR or go work on remodelling the bedroom, so I'll do a quick PR. |
The linked PR tweaks this commit, so this can be closed. I can't push to this branch, but I kept the commit which records dos65's contribution IIUC. Also apologies for my frustrated comment from a week ago. I don't remember what snag I hit in trying out the failed test? but although I know testing frameworks is thankless work, barriers to trivial contributions are also not good. "But if contributing was easy, everyone would do it!" |
@som-snytt Thanks! What about the moment with test output, I agree that it might be done better but don't think that is critical. |
Fixes #9374