-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Missing bounds check for transparent inline type parameters #10552
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
Maybe. Not easy to do though, as these type parameters are lost at the time we are allowed to check kinds (can't check early because of risk of cyclic references). So we might also accept this and close. |
Maybe when we inline it we can keep a dummy |
I'll close this for now. Revisit if someone wants to work on this. |
Another instance of this bug transparent inline def foo[A <: Int]: Int = valueOf[A]
@main def run = println(foo["hi"]) It should fail but compiles. |
Aren't these applications still available in Inlined#call when we do bounds checking? |
Indeed, the class Foo:
transparent inline def foo[A <: Int]: Int = valueOf[A]
def run = println(foo["hi"]) PackageDef(Ident(<empty>), List(
TypeDef(Foo,
Template(DefDef(<init>, List(List()), TypeTree(), Thicket(List())), List(
Apply(Select(New(TypeTree()), <init>), List())
), ValDef(_, Thicket(List()), Thicket(List())), List(
DefDef(foo, List(List(
TypeDef(A, TypeBoundsTree(TypeTree(), Ident(Int), Thicket(List())))
)), Ident(Int), TypeApply(Ident(valueOf), List(Ident(A))))
,
DefDef(run, List(), TypeTree(),
Apply(Ident(println), List(
Inlined(
+ TypeApply(Select(This(Ident(Foo)), foo), List(
+ SingletonTypeTree(Literal("hi"))
+ ))
, List(), TypeApply(Ident(valueOf), List(TypeTree())))
))
)
))
)
)) We could check them in post type before removing the call. |
Actually, this should be done in the Inliner just before/after inlining. Otherwise, we could end up losing the inlined tree due o an outer inline method dropping it. |
If an inlined tree is dropped I assume that's because it's dead code? If so I don't think it's a big deal if we don't check bounds in it since it doesn't affect soundness. |
It is not necessarily dead code. It might be code that a macro used as part of partial evaluation. Hence it was live code during compilation. |
I see thanks, can we come up with a test case demonstrating this for #12334 ? |
The tests do not compile due to a type bounds check See scala/scala3#10552
Minimized code
Output
Expectation
The error should also be emitted for
foo[List]
The text was updated successfully, but these errors were encountered: