Skip to content

Pattern matcher produces scope-incorrect code. #188

Closed
@odersky

Description

@odersky

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions