Skip to content

Pattern matcher does not generate ValDefs for defined pattern bound variables #190

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 · 4 comments
Closed
Assignees

Comments

@odersky
Copy link
Contributor

odersky commented Oct 13, 2014

When compiling pos/functions1.scala I observe the following code snippet

  val x33: String => String = {
    def $anonfun(x22: String): String = {
      case val selector11: String = x22
      {
        def case11(): String = {
          def case21(): String = {
            def matchFail11(): String = throw new MatchError(selector11)
            {
              x34
            }
          }
          if "abc".equals(selector11) then {
            val x21: String = selector11
            {
              ""
            }
          } else case21()
        }
        case11()
      }
    }
    closure($anonfun)
  }

You need to compile against the latest commit with the changed functions1.scala or else compile with -uniqid to observe the effect: In both cases, the definition of the pattern bound variable x34 is missing.

Detected when trying to lambda-lift this code.

@DarkDimius
Copy link
Contributor

@odersky can you please give a link to changed funtions1.scala?

@DarkDimius
Copy link
Contributor

I was able to reproduce. Fix upcomming.

@DarkDimius DarkDimius self-assigned this Oct 13, 2014
DarkDimius added a commit to dotty-staging/dotty that referenced this issue Oct 13, 2014
In scalac SubstOnlyTreeMakers were implemented using substitution,
and didn't actually introduce new trees.
Thus there was an optimization to remove them while generating code.

This optimization led to scala#190. It is now removed.
@DarkDimius
Copy link
Contributor

There was an optimization not applicable to dotty left in Pattern Matcher.
In scalac SubstOnlyTreeMakers aren't generating code, and an optimization was included to short-circuit them.
Why this is no longer applicable is explained in commit.

@DarkDimius
Copy link
Contributor

Fixed in #189

WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this issue May 8, 2025
Backport "Preserve hard unions in widenSingletons" 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