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

Case class with unusual field name kills the compiler #10625

Closed
dszakallas opened this issue Nov 24, 2017 · 6 comments
Closed

Case class with unusual field name kills the compiler #10625

dszakallas opened this issue Nov 24, 2017 · 6 comments

Comments

@dszakallas
Copy link

Welcome to Scala 2.12.4 (OpenJDK 64-Bit Server VM, Java 1.8.0_152).
Type in expressions for evaluation. Or try :help.

scala> case class A(`^$#`: Any)
ReplGlobal.abort: hash not in List(value hash)
error:
  hash not in List(value hash)
     while compiling: <console>
        during phase: constructors
     library version: version 2.12.4
    compiler version: version 2.12.4
  reconstructed args: -deprecation -feature

  last tree to typer: TypeTree(class Some)
       tree position: line 11 of <console>
            tree tpe: Some
              symbol: (final case) class Some in package scala
   symbol definition: final case class Some extends Option with Product with Serializable (a ClassSymbol)
      symbol package: scala
       symbol owners: class Some
           call site: class A in package $line3

<Cannot read source file>
scala.reflect.internal.FatalError:
  hash not in List(value hash)
     while compiling: <console>
        during phase: constructors
     library version: version 2.12.4
    compiler version: version 2.12.4
  reconstructed args: -deprecation -feature

  last tree to typer: TypeTree(class Some)
       tree position: line 11 of <console>
            tree tpe: Some
              symbol: (final case) class Some in package scala
   symbol definition: final case class Some extends Option with Product with Serializable (a ClassSymbol)
      symbol package: scala
       symbol owners: class Some
           call site: class A in package $line3

<Cannot read source file>
	at scala.reflect.internal.Reporting.abort(Reporting.scala:61)
	at scala.reflect.internal.Reporting.abort$(Reporting.scala:57)
	at scala.tools.nsc.interpreter.IMain$$anon$1.scala$tools$nsc$interpreter$ReplGlobal$$super$abort(IMain.scala:240)
	at scala.tools.nsc.interpreter.ReplGlobal.abort(ReplGlobal.scala:23)
	at scala.tools.nsc.interpreter.ReplGlobal.abort$(ReplGlobal.scala:21)
	at scala.tools.nsc.interpreter.IMain$$anon$1.abort(IMain.scala:240)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer.parameterNamed(Constructors.scala:483)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer.parameter(Constructors.scala:475)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer.$anonfun$transformed$3(Constructors.scala:731)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer.transformed(Constructors.scala:712)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.$anonfun$transform$1(Constructors.scala:85)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:30)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.transform(Constructors.scala:85)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.$anonfun$triage$4(Constructors.scala:651)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.triage(Constructors.scala:623)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.<init>(Constructors.scala:591)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer.transformed(Constructors.scala:694)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.$anonfun$transform$1(Constructors.scala:85)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:30)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.transform(Constructors.scala:85)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.$anonfun$triage$4(Constructors.scala:651)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.triage(Constructors.scala:623)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.<init>(Constructors.scala:591)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer.transformed(Constructors.scala:694)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.$anonfun$transform$1(Constructors.scala:85)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:30)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.transform(Constructors.scala:85)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.$anonfun$triage$4(Constructors.scala:651)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.triage(Constructors.scala:623)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer$Triage.<init>(Constructors.scala:591)
	at scala.tools.nsc.transform.Constructors$TemplateTransformer.transformed(Constructors.scala:694)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.$anonfun$transform$1(Constructors.scala:85)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:30)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.transform(Constructors.scala:85)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.transform(Constructors.scala:29)
	at scala.reflect.api.Trees$Transformer.$anonfun$transformStats$1(Trees.scala:2589)
	at scala.reflect.api.Trees$Transformer.transformStats(Trees.scala:2587)
	at scala.reflect.internal.Trees.$anonfun$itransform$7(Trees.scala:1438)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:30)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:25)
	at scala.reflect.internal.Trees.itransform(Trees.scala:1438)
	at scala.reflect.internal.Trees.itransform$(Trees.scala:1348)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
	at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:16)
	at scala.reflect.api.Trees$Transformer.transform(Trees.scala:2555)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.super$transform(TypingTransformers.scala:40)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.$anonfun$transform$2(TypingTransformers.scala:42)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:30)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:25)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.transform(Constructors.scala:89)
	at scala.tools.nsc.transform.Constructors$ConstructorTransformer.transform(Constructors.scala:29)
	at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:140)
	at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30)
	at scala.tools.nsc.Global$GlobalPhase.$anonfun$applyPhase$1(Global.scala:436)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:429)
	at scala.tools.nsc.Global$GlobalPhase.$anonfun$run$1(Global.scala:400)
	at scala.tools.nsc.Global$GlobalPhase.$anonfun$run$1$adapted(Global.scala:400)
	at scala.collection.Iterator.foreach(Iterator.scala:929)
	at scala.collection.Iterator.foreach$(Iterator.scala:929)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:400)
	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1452)
	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1436)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1429)
	at scala.tools.nsc.interpreter.IMain.compileSourcesKeepingRun(IMain.scala:431)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:800)
	at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:758)
	at scala.tools.nsc.interpreter.IMain$Request.compile$lzycompute(IMain.scala:947)
	at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:942)
	at scala.tools.nsc.interpreter.IMain.compile(IMain.scala:600)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:589)
	at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:561)
	at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:869)
	at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:737)
	at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:455)
	at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:476)
	at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:1052)
	at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:82)
	at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:85)
	at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
	at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
	at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

That entry seems to have slain the compiler.  Shall I replay
your session? I can re-run each line except the last one.
[y/n]
@hrhino
Copy link

hrhino commented Nov 24, 2017

But... why?

@dszakallas
Copy link
Author

dszakallas commented Nov 24, 2017

Why did I use such a name? Well I just wanted to try out whether Jackson's data binding for CSV works as I expect, and adheres to the alphabetic ordering of the mangled names, and I came up with such a name by accident. The original example had multiple fields of course.

@som-snytt
Copy link

The spec disallows embedded $, and says "host systems" may restrict back-quoted idents, but I wonder if it would be feasible and friendly to encode back-quoted a$# as a$dollar$hash. Our natural inclination is to enclose stuff in back-quotes and assume we're OK.

@SethTisue
Copy link
Member

if we had a better selective-warning-suppression story, maybe there could be a warning when you use $ in an identifier, like "you're going out of spec here, I hope you know what you're doing" type of thing.

I have an urge to simply close the bug with a "well don't do that", but it's really not ideal for the compiler to crash on this, there is certainly room for improvement here.

@som-snytt
Copy link

Closing in favor of #8831 which may not be exact duplicate but serves as umbrella for dollar-inducements.

@SethTisue
Copy link
Member

We are about to merge a PR (scala/scala#9008) that fixes #8831 without fixing this.

Regardless, I'm leaving this one closed since as @som-snytt indicates, this is actually within spec. Regardless, a PR that added a warning would be welcome, especially now that we have convenient warning suppression.

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

4 participants