From 746889b4ed0f53e433c123ddb2b90dece1298fff Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 22 Oct 2015 17:05:47 +0200 Subject: Check for cyclic inheritance. --- src/dotty/tools/dotc/typer/Namer.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/typer/Namer.scala') diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 3f732f80c..3c491fa7a 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -575,7 +575,14 @@ class Namer { typer: Typer => def checkedParentType(parent: untpd.Tree): Type = { val ptype = parentType(parent)(ctx.superCallContext) if (cls.isRefinementClass) ptype - else checkClassTypeWithStablePrefix(ptype, parent.pos, traitReq = parent ne parents.head) + else { + val pt = checkClassTypeWithStablePrefix(ptype, parent.pos, traitReq = parent ne parents.head) + if (pt.derivesFrom(cls)) { + ctx.error(i"cyclic inheritance: $cls extends itself", parent.pos) + defn.ObjectClass.typeRef + } + else pt + } } val selfInfo = -- cgit v1.2.3