-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Wrong match case selected #16252
Comments
This used to work in 3.1.3. |
The problem disappears if we replace |
Minimization without running class Baz:
inline def foo: Int = bar(zero)
inline def bar(inline i: Int): Int = inline i match
case 0 => 0
case _ => scala.compiletime.error("XD")
private inline def zero = 0
@main
def main =
println(Baz().foo) |
The regressing commit is 86bb972 |
How important is it? It was @nicolasstucki's commit, and I don't feel confident to propose an alternative. Do we need to revert #15075, reopening the other issue? Or can it wait? It's a difficult tradeoff. |
In fact, this should never have worked. Or rather, it does only work if the functions are declared inline def zero = 0 reduces to Otherwise put, if |
It's a little confusing to me that "disjointness" is a factor in match type reduction but not in inline matches. Makes it more work to remember the different semantics. I'm guessing it's required or perhaps much preferred. |
I agree. That's something we should discuss. |
Could someone explain the resolution? Is this behavior as expected? Why does |
It probably should not work with public methods either. There's a grey zone where the inline happens to reduce something because of some optimization or other. We might want to track these down and avoid them at some point, but it's tedious work for not much benefit. But in any case, if the method is not transparent, you can rely only on the result type, which is |
@odersky thank you for clarifying. A few more observations:
class Baz:
inline def foo: Int = bar(zero)
inline def bar(inline i: Int): Int = inline if i == 0 then 0 else 1
private inline def zero = 0
println(Baz().foo)
class Baz:
inline def foo: Int = bar(0)
inline def bar(inline i: Int): Int = inline if i == 0 then 0 else 1
println(Baz().foo)
class Baz:
inline def foo: Int = inline if 0 == 0 then 0 else 1
println(Baz().foo)
class Baz:
inline def foo: Int = 0
println(Baz().foo)
println(0) |
Compiler version
3.2.0
Minimized code
Output
1
Expectation
0
See also #15893
The text was updated successfully, but these errors were encountered: