@@ -94,7 +94,11 @@ object CheckCaptures:
94
94
/** Check that a @retains annotation only mentions references that can be tracked.
95
95
* This check is performed at Typer.
96
96
*/
97
- def checkWellformed (ann : Tree )(using Context ): Unit =
97
+ def checkWellformed (parent : Tree , ann : Tree )(using Context ): Unit =
98
+ parent.tpe match
99
+ case _ : SingletonType =>
100
+ report.error(em " Singleton type $parent cannot have capture set " , parent.srcPos)
101
+ case _ =>
98
102
for elem <- retainedElems(ann) do
99
103
elem.tpe match
100
104
case ref : CaptureRef =>
@@ -848,21 +852,25 @@ class CheckCaptures extends Recheck, SymTransformer:
848
852
adaptedType(boxed)
849
853
}
850
854
851
- var actualw = actual.widenDealias
852
- actual match
853
- case ref : CaptureRef if ref.isTracked =>
854
- actualw match
855
- case CapturingType (p, refs) if ref.singletonCaptureSet.mightSubcapture(refs) =>
856
- actualw = actualw.derivedCapturingType(p, ref.singletonCaptureSet)
857
- .showing(i " improve $actualw to $result" , capt)
858
- // given `a: C T`, improve `C T` to `{a} T`
859
- case _ =>
860
- case _ =>
861
- val adapted = adapt(actualw, expected, covariant = true )
862
- if adapted ne actualw then
863
- capt.println(i " adapt boxed $actual vs $expected ===> $adapted" )
864
- adapted
865
- else actual
855
+ if expected.isSingleton && actual.isSingleton then
856
+ println(i " shot $actual $expected" )
857
+ actual
858
+ else
859
+ var actualw = actual.widenDealias
860
+ actual match
861
+ case ref : CaptureRef if ref.isTracked =>
862
+ actualw match
863
+ case CapturingType (p, refs) if ref.singletonCaptureSet.mightSubcapture(refs) =>
864
+ actualw = actualw.derivedCapturingType(p, ref.singletonCaptureSet)
865
+ .showing(i " improve $actualw to $result" , capt)
866
+ // given `a: T^C`, improve `T^C` to `T^{a}`
867
+ case _ =>
868
+ case _ =>
869
+ val adapted = adapt(actualw, expected, covariant = true )
870
+ if adapted ne actualw then
871
+ capt.println(i " adapt boxed $actual vs $expected ===> $adapted" )
872
+ adapted
873
+ else actual
866
874
end adaptBoxed
867
875
868
876
/** Check overrides again, taking capture sets into account.
0 commit comments