Skip to content

inline val of null #12177

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
japgolly opened this issue Apr 21, 2021 · 4 comments · Fixed by #12192
Closed

inline val of null #12177

japgolly opened this issue Apr 21, 2021 · 4 comments · Fixed by #12192
Labels
area:inline area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement
Milestone

Comments

@japgolly
Copy link
Contributor

Compiler version

RC3

Minimized code

object Test1 {
  inline val v = null
  inline def d = null
}

Output

[error] 2 |  inline val v = null
[error]   |                 ^^^^
[error]   |                 inline value must contain a literal constant value.
[error]   |
[error]   |                 To inline more complex types consider using `inline def`
[error] one error found

Expectation

Want to check that this is really desired behaviour vs an oversight. null's are literal constants right? Literal(Constant(null)) is valid in the quoting API.

@bishabosha
Copy link
Member

bishabosha commented Apr 22, 2021

I guess the error message is misleading, an inline val needs to have a literal type, and there is no literal type for null

@bishabosha bishabosha added area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement and removed itype:bug labels Apr 22, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 22, 2021
@som-snytt
Copy link
Contributor

I would have expected null is literally the most literal type. I guess the same for unit and nothing.

@sjrd
Copy link
Member

sjrd commented Apr 22, 2021

Nothing doesn't have a value, so no. But I agree that null and () should have corresponding literal types, or at least that we should be able to use them in the same capacity as other literals.

@nicolasstucki
Copy link
Contributor

The current limitation for supporting inline val n = null and inline val u = () is that we o not guarantee constant folding on them as with literal types. We would need to start with that, created #12198 to track progress on this enhancement.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 23, 2021
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 24, 2021
@Kordyjan Kordyjan added this to the 3.0.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:inline area:reporting Error reporting including formatting, implicit suggestions, etc itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants