-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
erasedValue[V] does not work with function return type 'V' #19294
Comments
If |
Using // asInstanceOf is a workaround
inline def workaround[V]: V =
inline compiletime.erasedValue[V] match
case _: Int => 1.asInstanceOf[V]
case _ => compiletime.error("nope") |
asInstanceOf doesn't seem to add any overhead:
|
It would be nice to be able to match on |
It's not possible because it makes no sense. Types can be substituted for better types (i.e., subtypes) through inlining. If we allowed that kind of constraint, something that is valid before inlining might become invalid after inlining. |
A note about why the So in my repro example, the return type |
Compiler version
3.3.1
Minimized code
Output
The function
fails[V]: V
gives a compile error:Expectation
I was hoping to be able to specify return type (in this case
V
) as long as it is consistent with the inline-generated code. Note, I did also try usingtransparent inline def ...
but that does not work either.Just leaving the return type off is a possibility, but seems like an anti-pattern, and at least using
transparent inline
seems like it could properly check all the types at compile time.The text was updated successfully, but these errors were encountered: