question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong match case selected

See original GitHub issue

Compiler version

3.2.0

Minimized code

class Baz:
  inline def foo: Int = bar(zero)
  inline def bar(inline i: Int): Int = inline i match
    case 0 => 0
    case _ => 1
  private inline def zero = 0

println(Baz().foo)

Output

1

Expectation

0

See also #15893

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dwijnandcommented, Oct 30, 2022

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.

0reactions
Bersiercommented, Oct 31, 2022

@odersky thank you for clarifying.

A few more observations:

  1. This behavior (and how it differs from match type reduction) doesn’t currently seem to be fully documented.

  2. One might naively assume the inline match to be equivalent to inline if i == 0 then 0 else 1 (but the latter leads to a compile-time error).

  3. In both cases, it also seems at odds with the part of the documentation that says It guarantees that inlining actually happens instead of being best-effort. According to that statement, one might naively assume code reduction to proceed somewhat as follows:

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)

--> (because zero is guaranteed to be inlined)

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)

--> (because bar is guaranteed to be inlined)

class Baz:
  inline def foo: Int = inline if 0 == 0 then 0 else 1

println(Baz().foo)

--> (inline if reduction)

class Baz:
  inline def foo: Int = 0

println(Baz().foo)

--> (because foo is guaranteed to be inlined)

println(0)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make case sensitive match - SpreadsheetWeb
Start with =MATCH( function · Type TRUE, to search for matched values · Continue with EXACT( function · Select the reference that contains...
Read more >
Find.MatchCase property (Word) - Microsoft Learn
In this article. True if the find operation is case-sensitive. The default is False. Read/write Boolean.
Read more >
Thread: Match Case in Find does not work. - VBA Express
I am attempting to find text with no regards to case. ".MatchCase = False" (or true) does not work. This is what I...
Read more >
INDEX MATCH – Case sensitive - Get Digital Help
The MATCH function finds a specific value in an array or cell range and returns its location, a number representing the position.
Read more >
Excel MATCH Function Error Troubleshooting Examples
Sometimes, a MATCH formula returns an #N/A error, even if the value you're looking for is in the lookup table. The reason for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found