@@ -411,9 +411,23 @@ class Typer extends Namer
411
411
tree.withType(ownType)
412
412
}
413
413
414
+ checkStableIdentPattern(tree1, pt)
414
415
checkValue(tree1, pt)
415
416
}
416
417
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
+
417
431
private def typedSelect (tree : untpd.Select , pt : Type , qual : Tree )(implicit ctx : Context ): Select =
418
432
checkValue(assignType(cpy.Select (tree)(qual, tree.name), qual), pt)
419
433
@@ -423,7 +437,7 @@ class Typer extends Namer
423
437
val qual1 = typedExpr(tree.qualifier, selectionProto(tree.name, pt, this ))
424
438
if (tree.name.isTypeName) checkStable(qual1.tpe, qual1.pos)
425
439
val select = typedSelect(tree, pt, qual1)
426
- if (select.tpe ne TryDynamicCallType ) select
440
+ if (select.tpe ne TryDynamicCallType ) checkStableIdentPattern( select, pt)
427
441
else if (pt.isInstanceOf [PolyProto ] || pt.isInstanceOf [FunProto ] || pt == AssignProto ) select
428
442
else typedDynamicSelect(tree, Nil , pt)
429
443
}
0 commit comments