Skip to content

Commit 4630203

Browse files
committed
address review: move check to typer
1 parent 77ac75c commit 4630203

File tree

2 files changed

+15
-36
lines changed

2 files changed

+15
-36
lines changed

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

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,6 @@ object RefChecks {
7575
}
7676
}
7777

78-
/** Check that a stable identifier pattern is indeed stable (SLS 8.1.5)
79-
*/
80-
private def checkStableIdentPattern(tree: Tree)(implicit ctx: Context) = {
81-
def error = ctx.error(s"stable identifier required, but ${tree.show} found", tree.pos)
82-
tree match {
83-
case _: Ident if !isWildcardArg(tree) =>
84-
if (!tree.tpe.isStable) error
85-
case _: Select =>
86-
if (!tree.tpe.isStable) error
87-
case _: Apply =>
88-
error
89-
case _ =>
90-
}
91-
}
92-
9378
/** The this-type of `cls` which should be used when looking at the types of
9479
* inherited members. If `cls` has a non-trivial self type, this returns a skolem
9580
* with the class type instead of the `this-type` of the class as usual.
@@ -899,26 +884,6 @@ class RefChecks extends MiniPhase { thisPhase =>
899884
currentLevel.enterReference(sym, tree.pos)
900885
tree
901886
}
902-
903-
override def transformUnApply(tree: UnApply)(implicit ctx: Context): Tree = {
904-
tree.patterns.foreach(checkStableIdentPattern(_))
905-
tree
906-
}
907-
908-
override def transformAlternative(tree: Alternative)(implicit ctx: Context): Tree = {
909-
tree.trees.foreach(checkStableIdentPattern(_))
910-
tree
911-
}
912-
913-
override def transformBind(tree: Bind)(implicit ctx: Context): Tree = {
914-
checkStableIdentPattern(tree.body)
915-
tree
916-
}
917-
918-
override def transformCaseDef(tree: CaseDef)(implicit ctx: Context) = {
919-
checkStableIdentPattern(tree.pat)
920-
tree
921-
}
922887
}
923888

924889
/* todo: rewrite and re-enable

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,23 @@ class Typer extends Namer
406406
tree.withType(ownType)
407407
}
408408

409+
checkStableIdentPattern(tree1, pt)
409410
checkValue(tree1, pt)
410411
}
411412

413+
/** Check that a stable identifier pattern is indeed stable (SLS 8.1.5)
414+
*/
415+
private def checkStableIdentPattern(tree: Tree, pt: Type)(implicit ctx: Context): Tree = {
416+
if (ctx.mode.is(Mode.Pattern) &&
417+
!tree.isType &&
418+
!pt.isInstanceOf[ApplyingProto] &&
419+
!tree.tpe.isStable &&
420+
!isWildcardArg(tree))
421+
ctx.error(s"stable identifier required, but ${tree.show} found", tree.pos)
422+
423+
tree
424+
}
425+
412426
private def typedSelect(tree: untpd.Select, pt: Type, qual: Tree)(implicit ctx: Context): Select =
413427
checkValue(assignType(cpy.Select(tree)(qual, tree.name), qual), pt)
414428

@@ -418,7 +432,7 @@ class Typer extends Namer
418432
val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this))
419433
if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos)
420434
val select = typedSelect(tree, pt, qual1)
421-
if (select.tpe ne TryDynamicCallType) select
435+
if (select.tpe ne TryDynamicCallType) checkStableIdentPattern(select, pt)
422436
else if (pt.isInstanceOf[PolyProto] || pt.isInstanceOf[FunProto] || pt == AssignProto) select
423437
else typedDynamicSelect(tree, Nil, pt)
424438
}

0 commit comments

Comments
 (0)