Skip to content

Empty DefDef: Unit with end marker #12918

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

Closed
dos65 opened this issue Jun 23, 2021 · 2 comments
Closed

Empty DefDef: Unit with end marker #12918

dos65 opened this issue Jun 23, 2021 · 2 comments

Comments

@dos65
Copy link
Contributor

dos65 commented Jun 23, 2021

3.0.0-RC2

Should the compiler allow the following empty def?
Currently, it fails with an error from the parser.

 def foo: Unit = //<- [error] expression expected but end found
 end foo 
@som-snytt
Copy link
Contributor

som-snytt commented Jun 23, 2021

Related use case at #12185 (comment) which was about (transiently) empty class template during development. (Where empty template body after colon is allowed with end marker.)

What if the answer here is yes, but it expands to

def f: Unit =
  ???
end f

corresponding to the intention to fill in the blank later.

I don't think Unit is special here. If only "value discard" covered other singleton types, especially this.type.

def add(x: X): this.type =
end add

would I want a default implementation or NotImplemented? Also it looks like stack trace printing in REPL is broken.

@odersky
Copy link
Contributor

odersky commented Jun 24, 2021

Should the compiler allow the following empty def?

I think logically it should not. end markers an optional addition to a program. The program needs to be syntactically correct even if they are missing.

@odersky odersky closed this as completed Jun 24, 2021
@som-snytt som-snytt closed this as not planned Won't fix, can't repro, duplicate, stale Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants