diff options
author | Paul Phillips <paulp@improving.org> | 2010-02-27 23:49:51 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2010-02-27 23:49:51 +0000 |
commit | 7476ed45af6cf90f8c0e03f6ed429dcb436baf87 (patch) | |
tree | 4d89f0d765ecbc8851b10eee6e1b6d0662a16466 | |
parent | 646c478b3aeb05079c915c217272bcb64dc324fc (diff) | |
download | scala-7476ed45af6cf90f8c0e03f6ed429dcb436baf87.tar.gz scala-7476ed45af6cf90f8c0e03f6ed429dcb436baf87.tar.bz2 scala-7476ed45af6cf90f8c0e03f6ed429dcb436baf87.zip |
Expanded the check from #1392 to enclose #3123 ...
Expanded the check from #1392 to enclose #3123 as well so that "case Int
=> " doesn't crash. Closes #3123. Review by odersky.
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Symbols.scala | 7 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 | ||||
-rw-r--r-- | test/files/neg/bug3123.check | 4 | ||||
-rw-r--r-- | test/files/neg/bug3123.scala | 5 |
4 files changed, 20 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index c4407e1f0b..cbe3d3f172 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -386,6 +386,13 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => final def isVariable = isTerm && hasFlag(MUTABLE) && !isMethod + // See bugs #1392 and #3123 - this exists specifically to exclude the faux + // companion objects of scala.Int and etc. from appearing to be stable identifiers + // and then crashing the backend. This is surely better handled a different + // way (personally I would vote for making those companion objects real objects + // unless that is impossible.) + def isNotAValue = !isValue || (isModule && isValueClass(linkedClassOfModule)) + // interesting only for lambda lift. Captured variables are accessed from inner lambdas. final def isCapturedVariable = isVariable && hasFlag(CAPTURED) diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 504e940848..98ee29c32b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -642,16 +642,15 @@ trait Typers { self: Analyzer => * </ol> */ private def stabilize(tree: Tree, pre: Type, mode: Int, pt: Type): Tree = { - def isNotAValue(sym: Symbol) = // bug #1392 - !sym.isValue || (sym.isModule && isValueClass(sym.linkedClassOfModule)) - if (tree.symbol.hasFlag(OVERLOADED) && (mode & FUNmode) == 0) inferExprAlternative(tree, pt) val sym = tree.symbol + if (tree.tpe.isError) tree else if ((mode & (PATTERNmode | FUNmode)) == PATTERNmode && tree.isTerm) { // (1) - checkStable(tree) - } else if ((mode & (EXPRmode | QUALmode)) == EXPRmode && isNotAValue(sym) && !phase.erasedTypes) { // (2) + if (sym.isNotAValue) errorTree(tree, sym+" is not a value") + else checkStable(tree) + } else if ((mode & (EXPRmode | QUALmode)) == EXPRmode && sym.isNotAValue && !phase.erasedTypes) { // (2) errorTree(tree, sym+" is not a value") } else { if (sym.isStable && pre.isStable && tree.tpe.typeSymbol != ByNameParamClass && diff --git a/test/files/neg/bug3123.check b/test/files/neg/bug3123.check new file mode 100644 index 0000000000..8f5319c9a3 --- /dev/null +++ b/test/files/neg/bug3123.check @@ -0,0 +1,4 @@ +bug3123.scala:3: error: object Int is not a value + t match { case Int => true } + ^ +one error found diff --git a/test/files/neg/bug3123.scala b/test/files/neg/bug3123.scala new file mode 100644 index 0000000000..667a1da918 --- /dev/null +++ b/test/files/neg/bug3123.scala @@ -0,0 +1,5 @@ +object NotAValue { + def test[T](t : T) { + t match { case Int => true } + } +} |