Skip to content

Pattern matcher produces scope-incorrect code. #188

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

Closed
odersky opened this issue Oct 13, 2014 · 3 comments
Closed

Pattern matcher produces scope-incorrect code. #188

odersky opened this issue Oct 13, 2014 · 3 comments
Assignees

Comments

@odersky
Copy link
Contributor

odersky commented Oct 13, 2014

When compiling pos/Coder.scala the pattern matcher produces code like this

  private val charCode0$$local: scala.collection.immutable.Map = 
  Coder.this.mnemonics.withFilter({
    def $anonfun: (x$1: Tuple2)Boolean = {
      case val selector12: Tuple2 = x$1
      {
        def case31: ()Boolean = {
          {
            def case41: ()Boolean = {
              def matchFail21: ()Boolean = throw new MatchError(selector12)
              {
                false
              }
            }
            case41()
          }
          {
            val o32: Option = Tuple2.unapply[Char, String](selector12)
            if o32.isDefined.unary_! then {
              true
            } else case41()
          }
        }
        case31()
      }
    }
    closure($anonfun)
  }

Note the second reference to case41(),

} else case41()

That reference occurs outside the block in which case41 is defined. This makes changeOwner break,
because it substitutes symbols only in the scope where the symbol is defined. Consequently, after changeOwner, the definition of case41 gets a new symbol but the last reference still points to the old symbol. And this makes LambdaLift break.

@odersky
Copy link
Contributor Author

odersky commented Oct 13, 2014

Also, I have the strong suspicion that the unary_! in the code above is wrong. Maybe a consequence of going from isEmpty in Scala 2 to isDefined?

@DarkDimius DarkDimius self-assigned this Oct 13, 2014
DarkDimius added a commit to dotty-staging/dotty that referenced this issue Oct 13, 2014
@DarkDimius
Copy link
Contributor

@odersky thanks for noticing. Should be fixed in #189.
A scoping check seems to be a good addition to Ycheck.

@odersky
Copy link
Contributor Author

odersky commented Oct 14, 2014

Agreed we should add this to Ycheck.

WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this issue May 8, 2025
Backport "Fix scala#19907: Skip soft unions in widenSingle of widenInferred" to 3.3 LTS
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

No branches or pull requests

2 participants