Pattern `given` on the LHS of a `val` definition should enter corresponding scope
See original GitHub issueCompiler version
3.0.0-RC1
Minimized code
scala> given Int = 0
lazy val given_Int: Int
scala> def test = {
| val (x, given Int) = (1, 1)
| summon[Int]
| }
def test: Int
scala> test
val res0: Int = 0
Expectation
This is quite surprising/unexpected.
I would expect it to work in the same way as the following:
scala> def test = {
| given Int = 1
| summon[Int]
| }
def test: Int
scala> test
val res1: Int = 1
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Commands — Coq 8.16.1 documentation
This command can be used to filter the goal and the global context to retrieve ... The provided pattern or reference is matched...
Read more >Chapter 1 The core language - OCaml
The OCaml system computes both the value and the type for each phrase. ... The type inferred for sort, 'a list -> 'a...
Read more >Basic Declarations and Definitions
The scope of a name introduced by a declaration or definition is the whole ... Value definitions can alternatively have a pattern as...
Read more >SPARQL 1.1 Query Language - W3C
SPARQL can be used to express queries across diverse data sources, whether the data is stored natively as RDF or viewed as RDF...
Read more >Java Basics - Java Programming Tutorial
You can use the name to assign a value to the variable (e.g., radius = 1.2 ), and to ... Back-slash (Needed as...
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 Free
Top 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
Yes, but that’s totally unexpected from a user point of view.
I always thought the desugaring of local
val
bindings with patterns was unnecessarily convoluted and allocation-heavy.The correct approach would be to desugar them as:
Though this does not really generalize to member
val
s, which I am not convinced should be allowed to bind patterns anyway.Note: this would also mean that toplevel vals and object vals cannot be allowed to bind patterns. So a rather drastic change.