Permalink
Browse files

Hackaround for people who like to instantiate the uninstantiable.

Closes SI-5666 again.

(I don't have the least clue how I'm supposed to issue the error.)
  • Loading branch information...
paulp committed May 2, 2012
1 parent ae5ff66 commit e69ee3676dec6023a0d552a6dbabf9ffd29a7111
Showing with 32 additions and 1 deletion.
  1. +4 −0 src/compiler/scala/tools/nsc/typechecker/Typers.scala
  2. +28 −1 test/files/neg/t5666.check
@@ -3925,6 +3925,10 @@ trait Typers extends Modes with Adaptations with Taggings with PatMatVirtualiser
val sym = tp.typeSymbol.initialize
if (sym.isAbstractType || sym.hasAbstractFlag)
IsAbstractError(tree, sym)
else if (isPrimitiveValueClass(sym)) {
NotAMemberError(tpt, TypeTree(tp), nme.CONSTRUCTOR)
setError(tpt)
}
else if (!( tp == sym.thisSym.tpe // when there's no explicit self type -- with (#3612) or without self variable
// sym.thisSym.tpe == tp.typeOfThis (except for objects)
|| narrowRhs(tp) <:< tp.typeOfThis
View
@@ -4,7 +4,34 @@ t5666.scala:2: error: class Any is abstract; cannot be instantiated
t5666.scala:3: error: class AnyVal is abstract; cannot be instantiated
new AnyVal
^
t5666.scala:4: error: Double does not have a constructor
new Double
^
t5666.scala:5: error: Float does not have a constructor
new Float
^
t5666.scala:6: error: Long does not have a constructor
new Long
^
t5666.scala:7: error: Int does not have a constructor
new Int
^
t5666.scala:8: error: Char does not have a constructor
new Char
^
t5666.scala:9: error: Short does not have a constructor
new Short
^
t5666.scala:10: error: Byte does not have a constructor
new Byte
^
t5666.scala:11: error: Boolean does not have a constructor
new Boolean
^
t5666.scala:12: error: Unit does not have a constructor
new Unit
^
t5666.scala:13: error: class Nothing is abstract; cannot be instantiated
new Nothing
^
three errors found
12 errors found

1 comment on commit e69ee36

@soc

This comment has been minimized.

Show comment
Hide comment
@soc

soc May 2, 2012

Member

Thanks Paul. :-)

Member

soc commented on e69ee36 May 2, 2012

Thanks Paul. :-)

Please sign in to comment.