-
Notifications
You must be signed in to change notification settings - Fork 1.1k
constValueOpt doesn't work for class parameters #17387
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
This is not a bug. When the class is being compiled the compiler has no knowledge what |
Here is a better way: import scala.compiletime.*
class c2[i <: Int]:
inline def printme: Unit = println("constValueOpt:" + constValueOpt[i])
new c2[2].printme |
thanks for the reply, I know inline def will work,but feel that this limitation is not necessary. could you point me to the LOC in the compiler ? |
so according to the code, constValueOpt is only supported at inlinedMethod and it would be tricky to extend it ? |
Not part of the compiler team, but from what I understand, this is not something that is possible. |
@soronpo Just have an idea: why not get the value before compile time (maybe at macro expansion time ) and inline it when compiling ? |
Another solution is to use the ValueOf typeclass: class c2[i <: Int: ValueOf] { println("valueOf:" + valueOf[i]) } |
@smarter thanks! this looks interesting and almost same as what I think, but it will give errors:
|
What does the use-site look like? If it's def foo[i <: Int: ValueOf] = new c2[i] |
@smarter thanks! this actually works, it's just my typo |
Compiler version
3.2.2
Minimized code
Output
constValueOpt:None
Expectation
should be constValueOpt:Some(2)
The text was updated successfully, but these errors were encountered: