-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Comments
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 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 |
The error message should be improved. |
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 |
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. |
Fix #8841: Improve inline val error message
See #8850 |
May be there is a reason for this, but from usage prospective it is very confusing
The text was updated successfully, but these errors were encountered: