@@ -626,8 +626,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
626
626
val saved2 = foundUnderScala2
627
627
unimported = Set .empty
628
628
foundUnderScala2 = NoType
629
+ val excluded = if ctx.mode.is(Mode .InCaptureSet ) then EmptyFlags else CaptureParam
629
630
try
630
- val found = findRef(name, pt, EmptyFlags , EmptyFlags , tree.srcPos)
631
+ val found = findRef(name, pt, EmptyFlags , excluded , tree.srcPos)
631
632
if foundUnderScala2.exists && ! (foundUnderScala2 =:= found) then
632
633
report.migrationWarning(
633
634
em """ Name resolution will change.
@@ -715,11 +716,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
715
716
&& ctx.owner.owner.unforcedDecls.lookup(tree.name).exists
716
717
then // we are in the arguments of a this(...) constructor call
717
718
errorTree(tree, em " $tree is not accessible from constructor arguments " )
718
- else if name.isTermName && ctx.mode.is(Mode .InCaptureSet ) then
719
- // If we are in a capture set and the identifier is not a term name,
720
- // try to type it with the same name but as a type
721
- // typed(untpd.makeCapsOf(untpd.cpy.Ident(tree)(name.toTypeName)), pt)
722
- typed(untpd.cpy.Ident (tree)(name.toTypeName), pt)
723
719
else
724
720
errorTree(tree, MissingIdent (tree, kind, name, pt))
725
721
end typedIdent
@@ -925,13 +921,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
925
921
typedCBSelect(tree0, pt, qual)
926
922
else EmptyTree
927
923
928
- // Otherwise, if we are in a capture set, try to type it as a capture variable
929
- // reference (as selecting a type name).
930
- def trySelectTypeInCaptureSet () =
931
- if tree0.name.isTermName && ctx.mode.is(Mode .InCaptureSet ) then
932
- typedSelectWithAdapt(untpd.cpy.Select (tree0)(qual, tree0.name.toTypeName), pt, qual)
933
- else EmptyTree
934
-
935
924
// Otherwise, report an error
936
925
def reportAnError () =
937
926
assignType(tree,
@@ -953,7 +942,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
953
942
.orElse(tryDynamic())
954
943
.orElse(trySelectable())
955
944
.orElse(tryCBCompanion())
956
- .orElse(trySelectTypeInCaptureSet())
957
945
.orElse(reportAnError())
958
946
end typedSelectWithAdapt
959
947
@@ -2541,10 +2529,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2541
2529
2542
2530
def typedSingletonTypeTree (tree : untpd.SingletonTypeTree )(using Context ): Tree = {
2543
2531
val ref1 = typedExpr(tree.ref, SingletonTypeProto )
2544
- // println(i"typed singleton type $ref1 : ${ref1.tpe}, ${ctx.mode.is(Mode.InCaptureSet)}")
2545
- ref1.tpe match
2546
- case _ : TypeRef if ctx.mode.is(Mode .InCaptureSet ) => return ref1
2547
- case _ =>
2532
+ if ctx.mode.is(Mode .InCaptureSet ) && ref1.symbol.is(Flags .CaptureParam ) then
2533
+ // println(s"typedSingletonTypeTree: $ref1 -> ${ref1.tpe.widen}")
2534
+ return Ident (ref1.tpe.widen.asInstanceOf [TypeRef ]).withSpan(tree.span)
2548
2535
checkStable(ref1.tpe, tree.srcPos, " singleton type" )
2549
2536
assignType(cpy.SingletonTypeTree (tree)(ref1), ref1)
2550
2537
}
0 commit comments