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.

inline match breaks simple example, documentation?

See original GitHub issue

Compiler version

3.0.2

Minimized code

(transparent) inline def f(x: Int) = inline x match
  case 1 => 1
  case _ => 0

@main def m =
  val v = 1
  println(f(v))

Output

0

Expectation

Give the same output as (namely 1)

inline def f(x: Int) = x match
  case 1 => 1
  case _ => 0

and if not, be documented in the “Inline Matches” section of https://docs.scala-lang.org/scala3/reference/metaprogramming/inline.html.

(Note that this does work when v has singleton type 1)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolasstuckicommented, Oct 26, 2021

The documentation says If there is enough static information to unambiguously take a branch. In this case we only know that the type of x is Int. This implies that it is ambiguous as if the value is 1 then either branch would work and therefore we should not be able to reduce the inline match.

1reaction
bishaboshacommented, Oct 19, 2021

We can mention that inline match works on the static type of an expression, not its runtime type, hence matching the wildcard case when v == 1 but its type is Int

Read more comments on GitHub >

github_iconTop Results From Across the Web

4. More Control Flow Tools — Python 3.11.1 documentation
Only the first pattern that matches gets executed and it can also extract components (sequence elements or object attributes) from the value into...
Read more >
Basic Syntax - Markdown Guide
Line Breaks​​ To create a line break or new line ( <br> ), end a line with two or more spaces, and then...
Read more >
Pattern Matching | Tour of Scala - Scala Documentation
Pattern matching is a mechanism for checking a value against a pattern. A successful match can also deconstruct a value into its constituent...
Read more >
Quick reStructuredText - Docutils
Inline markup allows words and phrases within text to have character styles (like italics ... reference_, reference, A simple, one-word hyperlink reference.
Read more >
Evaluate a pattern match expression using the `switch ...
Learn about the C# `switch` expression that provides switch-like semantics based on pattern matching. You can compute a value based on which ...
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