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

Compiler crash on pattern matching in val definition #8395

Closed
scabug opened this issue Mar 12, 2014 · 6 comments
Closed

Compiler crash on pattern matching in val definition #8395

scabug opened this issue Mar 12, 2014 · 6 comments

Comments

@scabug
Copy link

scabug commented Mar 12, 2014

Provided code successfully compiles using 2.10.3 and crashes on 2.11.0-RC1:

    class Bar {
      def baz(x: Object) = {
        val s @ (_s: String) = x
      }
    }

Start of crash log:

    error: symbol value _s does not exist in Bar.baz
    error: scala.reflect.internal.FatalError:
      symbol value _s does not exist in Bar.baz
         while compiling: Bar.scala
            during phase: icode
         library version: version 2.11.0-RC1
        compiler version: version 2.11.0-RC1
      reconstructed args:

      last tree to typer: TypeTree(class String)
           tree position: line 3 of Bar.scala
                tree tpe: String
                  symbol: final class String in package lang
       symbol definition: final class String extends Serializable with Comparable with CharSequence (a ClassSymbol)
          symbol package: java.lang
           symbol owners: class String
               call site: constructor Bar in class Bar in package <empty>

    == Source file context for tree position ==

         0 class Bar {
         1   def baz(x: Object) = {
         2     val s @ (_s: String) = x
         3   }
         4 }
         5
      at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:57)
      at scala.tools.nsc.Global.abort(Global.scala:268)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadIdent$1(GenICode.scala:883)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:889)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1131)
      at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1129)
@scabug
Copy link
Author

scabug commented Mar 12, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8395?orig=1
Reporter: Vladimir Parfinenko (cypok)
Affected Versions: 2.11.0-M5, 2.11.0-RC1
Attachments:

  • log (created on Mar 12, 2014 9:44:58 AM UTC, 6184 bytes)

@scabug
Copy link
Author

scabug commented Mar 12, 2014

@retronym said:
Regressed somewhere in the name-based patmat change (scala/scala#2848)

@scabug
Copy link
Author

scabug commented Mar 12, 2014

@retronym said:

% scalac-hash v2.11.0-M4 -Xprint:patmat test/files/run/t8395.scala 2>&1 | tee sandbox/good.log
% scalac-hash v2.11.0-M5 -Xprint:patmat test/files/run/t8395.scala 2>&1 | tee sandbox/bad.log
% diff -U1000 sandbox/{good,bad}.log

--- sandbox/good.log	2014-03-12 11:21:11.000000000 +0100
+++ sandbox/bad.log	2014-03-12 11:21:00.000000000 +0100
@@ -1,34 +1,126 @@
 [[syntax trees at end of                    patmat]] // t8395.scala
 package <empty> {
   object Test extends scala.AnyRef {
     def <init>(): Test.type = {
       Test.super.<init>();
       ()
     };
     def baz(x: Object): Object = {
       <synthetic> <artifact> private[this] val x$1: (String, String) = {
         case <synthetic> val x1: Object = (x: Object @unchecked);
         case5(){
           if (x1.isInstanceOf[String])
             {
               <synthetic> val x2: String = (x1.asInstanceOf[String]: String);
-              matchEnd4(scala.Tuple2.apply[String, String](x1, x2))
+              matchEnd4(scala.Tuple2.apply[String, String](x2, _s))
             }
           else
             case6()
         };
         case6(){
           matchEnd4(throw new MatchError(x1))
         };
         matchEnd4(x: (String, String)){
           x
         }
       };
       val s: String = x$1._1;
       val _s: String = x$1._2;
       x
     };
     def main(args: Array[String]): Unit = scala.this.Predef.assert(Test.this.baz("1").==("1"))
   }
 }
 
+error: symbol value _s does not exist in Test.baz
+error: scala.reflect.internal.FatalError: 

@scabug
Copy link
Author

scabug commented Mar 12, 2014

@retronym said (edited on Mar 12, 2014 12:51:52 PM UTC):
Here's where we lose track of the _s:

https://github.com/scala/scala/pull/2848/files#diff-352de7f9c77a7e21df6940d6a1bcdc7eR62

      object SymbolAndTypeBound {
        def unapply(tree: Tree): Option[(Symbol, Type)] = tree match {
          case SymbolBound(sym, SymbolAndTypeBound(_, tpe)) => Some(sym -> tpe)
          case TypeBound(tpe)                               => Some(binder -> tpe)
          case _                                            => None
        }
      }

It vanishes into the _ ether on line 3.

@scabug
Copy link
Author

scabug commented Mar 12, 2014

@retronym said:
scala/scala#3622

@scabug
Copy link
Author

scabug commented Mar 12, 2014

@adriaanm said (edited on Mar 12, 2014 5:57:33 PM UTC):
Fly awayyyyy _s, fly awayyyyy. Where you going, _s -- come back here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants