Navigation Menu

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 when invoking a private constructor with invalid arguments #4987

Closed
scabug opened this issue Sep 11, 2011 · 9 comments
Closed
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Sep 11, 2011

If one invokes a private / protected constructor with an invalid number of arguments (or a mismatched signature), the compiler will crash with an "Unexpected New" exception.

@scabug
Copy link
Author

scabug commented Sep 11, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4987?orig=1
Reporter: @melezov
Affected Versions: 2.9.1, 2.10.0
Other Milestones: 2.10.0
Attachments:

  • crash.log (created on Sep 11, 2011 12:58:56 AM UTC, 7668 bytes)
  • FooBar.scala (created on Sep 11, 2011 12:44:51 AM UTC, 258 bytes)

@scabug
Copy link
Author

scabug commented Sep 11, 2011

@melezov said:
Compiler crash output

@scabug
Copy link
Author

scabug commented Sep 12, 2011

@melezov said (edited on Sep 12, 2011 1:51:09 PM UTC):
This also seems to occur when the arguments sent to the private/protected constructor match the signature, but only if there is more than one:

/* This will not crash, but rather complain, which is OK */
class Foo private (a: Int)
object Bar { new Foo(0) }

/* This will slay the compiler */
class Foo2 private (a: Int, b: Int)
object Bar2 { new Foo2(0, 0) }

@scabug
Copy link
Author

scabug commented Oct 30, 2011

@paulp said:
See also duplicates #4645, #4685, #4707, #5058, especially my comment in #4645. Consolidated under this one.

@scabug
Copy link
Author

scabug commented Oct 31, 2011

@paulp said:
See also #5063, which is not exactly the same bug but should be considered when fixing this one.

@scabug
Copy link
Author

scabug commented Mar 21, 2012

@odersky said (edited on Mar 21, 2012 2:58:15 PM UTC):
I can't reproduce it. Seems it has been fixed in the meantime? When I compile FooBar.scala, I get

/Users/odersky/Downloads/FooBar.scala:9: error: constructor Foo in class Foo cannot be accessed in object Bar
new Foo(null, null)
^
one error found

@scabug
Copy link
Author

scabug commented Mar 21, 2012

@soc said:
Also crashes on Scala version 2.10.0-M2-0152-g5dca64cefe-2012-03-13.

error: Unexpected New(TypeTree class $read$Foo2/Foo2) received in icode.
  Call was genLoad(new Foo2,	package: $line2
	clazz: Bar2
	method: Bar2.<init>
	bb: 1
	labels: Map()
	exception handlers: List()
	cleanups: List()
	scope: [][][]
,REF(class Object))
error: 
     while compiling:  <console>
       current phase:  icode
     library version:  version 2.10.0-M2-0152-g5dca64cefe-2012-03-13
    compiler version:  version 2.10.0-M2-0152-g5dca64cefe-2012-03-13
  reconstructed args:  

uncaught exception during compilation: scala.reflect.internal.FatalError
scala.reflect.internal.FatalError: 
     while compiling:  <console>
       current phase:  icode
     library version:  version 2.10.0-M2-0152-g5dca64cefe-2012-03-13
    compiler version:  version 2.10.0-M2-0152-g5dca64cefe-2012-03-13
  reconstructed args:  

Unexpected New(TypeTree class $read$$iw$$iw$Foo2/$line1.$read$$iw$$iw$Foo2) received in icode.
  Call was genLoad(new $line1.$read$$iw$$iw$Foo2,	package: $line2
	clazz: $line2.$read$$iw$$iw$Bar2
	method: $line2.$read$$iw$$iw$Bar2.<init>
	bb: 1
	labels: Map()
	exception handlers: List()
	cleanups: List()
	scope: [][][]
,REF(class Object))
	at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:38)
	at scala.tools.nsc.Global.abort(Global.scala:189)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:707)
	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$genLoadArguments$1.apply(GenICode.scala:1200)

@scabug
Copy link
Author

scabug commented Mar 21, 2012

@paulp said:
It does crash until very recently, but not in master.

// 2.10.0-20120320-201545-fcc63e2b66
scalac ./a.scala 
./a.scala:10: error: constructor Foo2 in class Foo2 cannot be accessed in object Bar2
object Bar2 { new Foo2(0, 0) }
              ^
one error found

@scabug
Copy link
Author

scabug commented Mar 22, 2012

@paulp said:
fb788e03f6

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