Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ValDef span assignment in PatternMatcher #15783

Merged
merged 1 commit into from
Jul 28, 2022
Merged

Conversation

Florian3k
Copy link
Contributor

Fixes #15535

Problem was in ValDef creation in PatternMatcher.
When the following code

def m(x: Int): Unit = 
  {
    x match 
      {
        case y @ _ => 
          println(y)
          println(y)
      }
  }

gets transformed to

def m(x: Int): Unit = 
  {
    matchResult1[Unit]: 
      {
        case val x1: (x : Int) = x
        case val y: Int = x1
        return[matchResult1] 
          {
            println(y)
            println(y)
          }
      }
  }

there are new ValDefs created for x1 and y. Their spans are assigned by Positioned.envelope based on spans of ValDef's fields. Those spans not always exist. In that case, span is assigned in seq function based on span of the block, which is usually incorrect.

Solution is to set ValDef's span to the span of original TermSymbol from which current val is being created.

@Florian3k Florian3k requested a review from dwijnand July 28, 2022 12:15
@Florian3k Florian3k merged commit 34f56c2 into scala:main Jul 28, 2022
@Florian3k Florian3k deleted the fix-15535 branch July 28, 2022 15:05
@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong debug line number in the body of a CaseDef
3 participants