@@ -411,9 +411,23 @@ class Typer extends Namer
411411 tree.withType(ownType)
412412 }
413413
414+ checkStableIdentPattern(tree1, pt)
414415 checkValue(tree1, pt)
415416 }
416417
418+ /** Check that a stable identifier pattern is indeed stable (SLS 8.1.5)
419+ */
420+ private def checkStableIdentPattern (tree : Tree , pt : Type )(implicit ctx : Context ): Tree = {
421+ if (ctx.mode.is(Mode .Pattern ) &&
422+ ! tree.isType &&
423+ ! pt.isInstanceOf [ApplyingProto ] &&
424+ ! tree.tpe.isStable &&
425+ ! isWildcardArg(tree))
426+ ctx.error(s " stable identifier required, but ${tree.show} found " , tree.pos)
427+
428+ tree
429+ }
430+
417431 private def typedSelect (tree : untpd.Select , pt : Type , qual : Tree )(implicit ctx : Context ): Select =
418432 checkValue(assignType(cpy.Select (tree)(qual, tree.name), qual), pt)
419433
@@ -423,7 +437,7 @@ class Typer extends Namer
423437 val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this ))
424438 if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos)
425439 val select = typedSelect(tree, pt, qual1)
426- if (select.tpe ne TryDynamicCallType ) select
440+ if (select.tpe ne TryDynamicCallType ) checkStableIdentPattern( select, pt)
427441 else if (pt.isInstanceOf [PolyProto ] || pt.isInstanceOf [FunProto ] || pt == AssignProto ) select
428442 else typedDynamicSelect(tree, Nil , pt)
429443 }
0 commit comments