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 trying to access private constructor #4685

Closed
scabug opened this issue Jun 9, 2011 · 6 comments
Closed

Compiler crash trying to access private constructor #4685

scabug opened this issue Jun 9, 2011 · 6 comments

Comments

@scabug
Copy link

scabug commented Jun 9, 2011

When trying to access a private constructor with more than one parameter the compiler crashes.
Can be reproduced with:

// file: Crash.scala
class Foo private (i: Int, j:Int)

class Bar {
val c = new Foo(1, 2)
}
// end file

$ scalac Crash.scala
error: java.lang.Error: Unexpected New
at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:35)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:725)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1226)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1224)
at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
at scala.collection.immutable.List.foldLeft(List.scala:45)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadArguments(GenICode.scala:1224)

$ scalac -version
Scala compiler version 2.9.0.1 -- Copyright 2002-2011, LAMP/EPFL

@scabug
Copy link
Author

scabug commented Jun 9, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4685?orig=1
Reporter: Jan van der Vorst (janvandervorst)
Affected Versions: 2.9.0

@scabug
Copy link
Author

scabug commented Jun 9, 2011

Jan van der Vorst (janvandervorst) said:
Just checked that the crash occurs since version 2.9.0

@scabug
Copy link
Author

scabug commented Jun 10, 2011

@paulp said:
Hijinx break out in typer when it goes hunting for a way to satisfy new Foo(1, 2). Only happens if Foo has no non-private constructors and at least two constructor parameters.

?{val this: ?}? is an interesting thing to be looking for.

Beginning implicit search for new Foo expecting (Foo) => ?{val this: ?} looking for a view
 ...
    typed implicit scala.this.Predef.any2stringadd(<argument>):scala.runtime.StringAdd, pt = (Foo) => ?{val this: ?}
    adapted implicit method any2stringadd:(x: Any)scala.runtime.StringAdd to (Foo) => ?{val this: ?}
    tvars = List()/List()
RESULT = SearchResult(scala.this.Predef.any2stringadd, TreeTypeSubstituter(List(),List()))

@scabug
Copy link
Author

scabug commented Jul 12, 2011

Norman Walsh (ndw) said:
For what it's worth, I'm seeing this bug in some code that doesn't have any private constructors. If someone's working on it, I can send a test case.

@scabug
Copy link
Author

scabug commented Jul 13, 2011

Norman Walsh (ndw) said:
I downloaded the 2.8.1-final version of the compiler to see if that would help me find the problem. Success!

Off in some stale testing code, I had written

val id = new InputDeclaration("input", false, DOCUMENT, "//*")

As I'd made progress, I'd made the InputDeclaration constructor "protected[model]" and changed its arguments. The 2.8.1-final compiler objected:

src/com/xmlcalabash/driver/Test.scala:29: error: overloaded method constructor InputDeclaration with alternatives:
(parent: com.xmlcalabash.model.Artifact,portName: String,sequence: Boolean,kind: com.xmlcalabash.model.DocumentKind.DocumentKind,select: String,primary: Boolean)com.xmlcalabash.model.InputDeclaration
(parent: com.xmlcalabash.model.Artifact,portName: String,isSeq: Boolean,docKind: com.xmlcalabash.model.DocumentKind.DocumentKind,selectExpr: String)com.xmlcalabash.model.InputDeclaration
cannot be applied to (java.lang.String, Boolean, com.xmlcalabash.model.DocumentKind.Value, java.lang.String)
val id = new InputDeclaration("input", false, DOCUMENT, "//*")

Removing my out-of-date and bogus testing code seems to have resolved the 2.9.0.1 compiler crash.

Hope that helps.

@scabug
Copy link
Author

scabug commented Oct 30, 2011

@paulp said:
#4645, #4685, #4707, #4987, #5058 are all the same bug. Consolidating under #4987.

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