diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 8 | ||||
-rw-r--r-- | test/files/neg/t3614.check | 4 | ||||
-rw-r--r-- | test/files/neg/t5361.check | 4 | ||||
-rw-r--r-- | test/files/neg/t5361.scala | 3 |
4 files changed, 16 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 5714c2c109..e358917aef 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2710,6 +2710,12 @@ trait Typers extends Modes with Adaptations with Tags { def typedRefinement(templ: Template) { val stats = templ.body namer.enterSyms(stats) + + // This is also checked later in typedStats, but that is too late for SI-5361, so + // we eagerly check this here. + for (stat <- stats if !treeInfo.isDeclarationOrTypeDef(stat)) + OnlyDeclarationsError(stat) + // need to delay rest of typedRefinement to avoid cyclic reference errors unit.toCheck += { () => val stats1 = typedStats(stats, NoSymbol) @@ -5068,7 +5074,7 @@ trait Typers extends Modes with Adaptations with Tags { val self = refinedType(parents1 map (_.tpe), context.enclClass.owner, decls, templ.pos) newTyper(context.make(templ, self.typeSymbol, decls)).typedRefinement(templ) templ updateAttachment CompoundTypeTreeOriginalAttachment(parents1, Nil) // stats are set elsewhere - tree setType self + tree setType (if (templ.exists(_.isErroneous)) ErrorType else self) // Being conservative to avoid SI-5361 } } diff --git a/test/files/neg/t3614.check b/test/files/neg/t3614.check index 0f9c83aa0d..81628ef37f 100644 --- a/test/files/neg/t3614.check +++ b/test/files/neg/t3614.check @@ -1,4 +1,4 @@ -t3614.scala:2: error: class type required but AnyRef{def a: Int} found +t3614.scala:2: error: only declarations allowed here def v = new ({ def a=0 }) - ^ + ^ one error found diff --git a/test/files/neg/t5361.check b/test/files/neg/t5361.check new file mode 100644 index 0000000000..d7fee87ccd --- /dev/null +++ b/test/files/neg/t5361.check @@ -0,0 +1,4 @@ +t5361.scala:2: error: only declarations allowed here + val x : { val self = this } = new { self => } + ^ +one error found diff --git a/test/files/neg/t5361.scala b/test/files/neg/t5361.scala new file mode 100644 index 0000000000..1705c09df3 --- /dev/null +++ b/test/files/neg/t5361.scala @@ -0,0 +1,3 @@ +class A { + val x : { val self = this } = new { self => } +} |