Skip to content

Commit 6136794

Browse files
committed
Merge pull request #469 from dotty-staging/stylecheck
Add stylechecking to test suite, fix style errors
1 parent 52d6ac3 commit 6136794

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,20 @@ trait Checking {
241241
def checkLegalPrefix(tp: Type, selector: Name, pos: Position)(implicit ctx: Context): Unit =
242242
if (!tp.isLegalPrefixFor(selector)) ctx.error(d"$tp is not a valid prefix for '# $selector'", pos)
243243

244-
/** Check that `tp` is a class type with a stable prefix. Also, if `traitReq` is
245-
* true check that `tp` is a trait.
244+
/** Check that `tp` is a class type with a stable prefix. Also:
245+
* If `traitReq` is true, check that `tp` refers to a trait.
246+
* If `concreteReq` is true, check that `tp` refers to a nonAbstract class.
246247
* Stability checking is disabled in phases after RefChecks.
247248
* @return `tp` itself if it is a class or trait ref, ObjectClass.typeRef if not.
248249
*/
249-
def checkClassTypeWithStablePrefix(tp: Type, pos: Position, traitReq: Boolean)(implicit ctx: Context): Type =
250+
def checkClassTypeWithStablePrefix(tp: Type, pos: Position, traitReq: Boolean = false, concreteReq: Boolean = false)(implicit ctx: Context): Type =
250251
tp.underlyingClassRef(refinementOK = false) match {
251252
case tref: TypeRef =>
252253
if (ctx.phase <= ctx.refchecksPhase) checkStable(tref.prefix, pos)
253-
if (traitReq && !(tref.symbol is Trait)) ctx.error(d"$tref is not a trait", pos)
254+
if (traitReq && !(tref.symbol is Trait))
255+
ctx.error(d"$tref is not a trait", pos)
256+
if (concreteReq && false && (tref.symbol is AbstractOrTrait))
257+
ctx.error(d"${tref.symbol} is abstract; cannot be instantiated, owner = ${ctx.owner}", pos)
254258
tp
255259
case _ =>
256260
ctx.error(d"$tp is not a class type", pos)
@@ -329,7 +333,7 @@ trait NoChecking extends Checking {
329333
override def checkBounds(args: List[tpd.Tree], poly: PolyType)(implicit ctx: Context): Unit = ()
330334
override def checkStable(tp: Type, pos: Position)(implicit ctx: Context): Unit = ()
331335
override def checkLegalPrefix(tp: Type, selector: Name, pos: Position)(implicit ctx: Context): Unit = ()
332-
override def checkClassTypeWithStablePrefix(tp: Type, pos: Position, traitReq: Boolean)(implicit ctx: Context): Type = tp
336+
override def checkClassTypeWithStablePrefix(tp: Type, pos: Position, traitReq: Boolean, concreteReq: Boolean)(implicit ctx: Context): Type = tp
333337
override def checkImplicitParamsNotSingletons(vparamss: List[List[ValDef]])(implicit ctx: Context): Unit = ()
334338
override def checkFeasible(tp: Type, pos: Position, where: => String = "")(implicit ctx: Context): Type = tp
335339
override def checkNoDoubleDefs(cls: Symbol)(implicit ctx: Context): Unit = ()

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
347347
val clsDef = TypeDef(x, templ).withFlags(Final)
348348
typed(cpy.Block(tree)(clsDef :: Nil, New(Ident(x), Nil)), pt)
349349
case _ =>
350-
val tpt1 = typedType(tree.tpt)
351-
checkClassTypeWithStablePrefix(tpt1.tpe, tpt1.pos, traitReq = false)
350+
val tpt1 = typedType(tree.tpt)
351+
checkClassTypeWithStablePrefix(tpt1.tpe, tpt1.pos, concreteReq = !ctx.owner.isClass)
352352
assignType(cpy.New(tree)(tpt1), tpt1)
353353
// todo in a later phase: checkInstantiatable(cls, tpt1.pos)
354354
}

0 commit comments

Comments
 (0)