Skip to content

Inline val does not allow explicit type #8841

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
edolgy opened this issue Apr 30, 2020 · 5 comments
Closed

Inline val does not allow explicit type #8841

edolgy opened this issue Apr 30, 2020 · 5 comments
Assignees

Comments

@edolgy
Copy link

edolgy commented Apr 30, 2020

inline val log1 : Boolean = false // Fails with: type of inline must be a known value

inline val log2  = false // Works fine

May be there is a reason for this, but from usage prospective it is very confusing

@nicolasstucki
Copy link
Contributor

Yes, there is a good reason for this. Inline values need a constant type because they are inlined by constant folding on literal constant types.

Previously we used final val for this purpose.

final val log1 : Boolean = false // Does not inline
final val log2  = false // Is inlined, equivalent to log3
final val log3: false = false // Is inlined

With inline vals we ensure that they can be inlined

inline val log1 : Boolean = false // error
inline val log2  = false // Is inlined, equivalent to log3
inline val log3: false = false // Is inlined

@nicolasstucki
Copy link
Contributor

The error message should be improved.

@nicolasstucki nicolasstucki self-assigned this Apr 30, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 30, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Apr 30, 2020
@edolgy
Copy link
Author

edolgy commented Apr 30, 2020

From language prospective a type like "false.type" makes perfect sense, but from usage prospective it does not

One would think of it as a Boolean, use it where Boolean is applicable.

Yes, the "true type" must be a constant expression, whatever it is, but the usage type might be more general-useful definition

Just an opinion, I am happy with either outcome

@nicolasstucki
Copy link
Contributor

Now that we are aligning the inline vals with the inline def it might be possible to do so. Though we should carefully analyse if that would be sound in general, which seems to be the case.

Also, this would help us with some other usability issues. I will open another issue for this possible usability enhancement.

nicolasstucki added a commit that referenced this issue May 1, 2020
Fix #8841: Improve inline val error message
@nicolasstucki
Copy link
Contributor

See #8850

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

2 participants