Skip to content

Commit c3c17ef

Browse files
committed
Fix tests
1 parent 460d01e commit c3c17ef

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
325325
// Check the constructor type as well; it could be an illegal singleton type
326326
// which would not be reflected as `tree.tpe`
327327
ctx.typer.checkClassType(nu.tpe, tree.srcPos, traitReq = false, stablePrefixReq = false)
328-
Checking.checkInstantiable(nu.tpe, nu.srcPos)
328+
Checking.checkInstantiable(tree.tpe, nu.tpe, nu.srcPos)
329329
withNoCheckNews(nu :: Nil)(app1)
330330
case _ =>
331331
app1
@@ -413,7 +413,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
413413
Checking.checkGoodBounds(tree.symbol)
414414
super.transform(tree)
415415
case tree: New if isCheckable(tree) =>
416-
Checking.checkInstantiable(tree.tpe, tree.srcPos)
416+
Checking.checkInstantiable(tree.tpe, tree.tpe, tree.srcPos)
417417
super.transform(tree)
418418
case tree: Closure if !tree.tpt.isEmpty =>
419419
Checking.checkRealizable(tree.tpt.tpe, tree.srcPos, "SAM type")

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,14 @@ object Checking {
185185
/** Check that `tp` refers to a nonAbstract class
186186
* and that the instance conforms to the self type of the created class.
187187
*/
188-
def checkInstantiable(tp: Type, pos: SrcPos)(using Context): Unit =
188+
def checkInstantiable(tp: Type, srcTp: Type, pos: SrcPos)(using Context): Unit =
189189
tp.underlyingClassRef(refinementOK = false) match
190190
case tref: TypeRef =>
191191
val cls = tref.symbol
192-
if (cls.isOneOf(AbstractOrTrait))
193-
report.error(CantInstantiateAbstractClassOrTrait(cls, isTrait = cls.is(Trait)), pos)
192+
if (cls.isOneOf(AbstractOrTrait)) {
193+
val srcCls = srcTp.underlyingClassRef(refinementOK = false).asInstanceOf[TypeRef].symbol
194+
report.error(CantInstantiateAbstractClassOrTrait(srcCls, isTrait = srcCls.is(Trait)), pos)
195+
}
194196
if !cls.is(Module) then
195197
// Create a synthetic singleton type instance, and check whether
196198
// it conforms to the self type of the class as seen from that instance.

0 commit comments

Comments
 (0)