@@ -1321,44 +1321,49 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
13211321 val parentsWithClass = ensureFirstIsClass(parents mapconserve typedParent, cdef.namePos)
13221322 val parents1 = ensureConstrCall(cls, parentsWithClass)(superCtx)
13231323 val self1 = typed(self)(ctx.outer).asInstanceOf [ValDef ] // outer context where class members are not visible
1324- val dummy = localDummy(cls, impl)
1325- val body1 = typedStats(impl.body, dummy)(inClassContext(self1.symbol))
1326- cls.setNoInitsFlags((NoInitsInterface /: body1)((fs, stat) => fs & defKind(stat)))
1327-
1328- // Expand comments and type usecases
1329- cookComments(body1.map(_.symbol), self1.symbol)(localContext(cdef, cls).setNewScope)
1330-
1331- checkNoDoubleDefs(cls)
1332- val impl1 = cpy.Template (impl)(constr1, parents1, self1, body1)
1333- .withType(dummy.nonMemberTermRef)
1334- checkVariance(impl1)
1335- if (! cls.is(AbstractOrTrait ) && ! ctx.isAfterTyper) checkRealizableBounds(cls.typeRef, cdef.namePos)
1336- val cdef1 = assignType(cpy.TypeDef (cdef)(name, impl1), cls)
1337- if (ctx.phase.isTyper && cdef1.tpe.derivesFrom(defn.DynamicClass ) && ! ctx.dynamicsEnabled) {
1338- val isRequired = parents1.exists(_.tpe.isRef(defn.DynamicClass ))
1339- ctx.featureWarning(nme.dynamics.toString, " extension of type scala.Dynamic" , isScala2Feature = true ,
1324+ if (self1.tpt.tpe.isError) {
1325+ // fail fast to avoid typing the body with an error type
1326+ cdef.withType(UnspecifiedErrorType )
1327+ } else {
1328+ val dummy = localDummy(cls, impl)
1329+ val body1 = typedStats(impl.body, dummy)(inClassContext(self1.symbol))
1330+ cls.setNoInitsFlags((NoInitsInterface /: body1) ((fs, stat) => fs & defKind(stat)))
1331+
1332+ // Expand comments and type usecases
1333+ cookComments(body1.map(_.symbol), self1.symbol)(localContext(cdef, cls).setNewScope)
1334+
1335+ checkNoDoubleDefs(cls)
1336+ val impl1 = cpy.Template (impl)(constr1, parents1, self1, body1)
1337+ .withType(dummy.nonMemberTermRef)
1338+ checkVariance(impl1)
1339+ if (! cls.is(AbstractOrTrait ) && ! ctx.isAfterTyper) checkRealizableBounds(cls.typeRef, cdef.namePos)
1340+ val cdef1 = assignType(cpy.TypeDef (cdef)(name, impl1), cls)
1341+ if (ctx.phase.isTyper && cdef1.tpe.derivesFrom(defn.DynamicClass ) && ! ctx.dynamicsEnabled) {
1342+ val isRequired = parents1.exists(_.tpe.isRef(defn.DynamicClass ))
1343+ ctx.featureWarning(nme.dynamics.toString, " extension of type scala.Dynamic" , isScala2Feature = true ,
13401344 cls, isRequired, cdef.pos)
1341- }
1345+ }
13421346
1343- // Check that phantom lattices are defined in a static object
1344- if (cls.classParents.exists(_.classSymbol eq defn.PhantomClass ) && ! cls.isStaticOwner)
1345- ctx.error(" only static objects can extend scala.Phantom" , cdef.pos)
1347+ // Check that phantom lattices are defined in a static object
1348+ if (cls.classParents.exists(_.classSymbol eq defn.PhantomClass ) && ! cls.isStaticOwner)
1349+ ctx.error(" only static objects can extend scala.Phantom" , cdef.pos)
13461350
1347- // check value class constraints
1348- checkDerivedValueClass(cls, body1)
1351+ // check value class constraints
1352+ checkDerivedValueClass(cls, body1)
13491353
1350- if (ctx.settings.YretainTrees .value) {
1351- cls.myTree = cdef1
1354+ if (ctx.settings.YretainTrees .value) {
1355+ cls.myTree = cdef1
1356+ }
1357+ cdef1
1358+
1359+ // todo later: check that
1360+ // 1. If class is non-abstract, it is instantiatable:
1361+ // - self type is s supertype of own type
1362+ // - all type members have consistent bounds
1363+ // 2. all private type members have consistent bounds
1364+ // 3. Types do not override classes.
1365+ // 4. Polymorphic type defs override nothing.
13521366 }
1353- cdef1
1354-
1355- // todo later: check that
1356- // 1. If class is non-abstract, it is instantiatable:
1357- // - self type is s supertype of own type
1358- // - all type members have consistent bounds
1359- // 2. all private type members have consistent bounds
1360- // 3. Types do not override classes.
1361- // 4. Polymorphic type defs override nothing.
13621367 }
13631368
13641369 /** Ensure that the first type in a list of parent types Ps points to a non-trait class.
0 commit comments