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.

Pattern `given` on the LHS of a `val` definition should enter corresponding scope

See original GitHub issue

Compiler 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:closed
  • Created 2 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
LPTKcommented, Mar 26, 2021

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:

def test = {
  (1, 1) match
  case (x, given Int) =>
    summon[Int]
    ... // rest of the block
}

Though this does not really generalize to member vals, which I am not convinced should be allowed to bind patterns anyway.

1reaction
oderskycommented, Mar 26, 2021

Though this does not really generalize to member vals, 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.

Read more comments on GitHub >

github_iconTop 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 >

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