inline match breaks simple example, documentation?
See original GitHub issueCompiler 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:
- Created 2 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The documentation says
If there is enough static information to unambiguously take a branch
. In this case we only know that the type ofx
isInt
. 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 theinline match
.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 isInt