Skip to content

Commit 8ed4527

Browse files
committed
Simplify ParamRef disambiguation
1 parent fa03916 commit 8ed4527

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

compiler/src/dotty/tools/dotc/reporting/Message.scala

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ object Message:
6262
*/
6363
private class Seen(disambiguate: Disambiguation):
6464

65-
/** The set of lambdas that were opened at some point during printing. */
66-
private val openedLambdas = new collection.mutable.HashSet[LambdaType]
67-
68-
/** Register that `tp` was opened during printing. */
69-
def openLambda(tp: LambdaType): Unit =
70-
openedLambdas += tp
71-
7265
val seen = new collection.mutable.HashMap[SeenKey, List[Recorded]].withDefaultValue(Nil)
7366

7467
var nonSensical = false
@@ -109,16 +102,17 @@ object Message:
109102
lazy val dealiased = followAlias(entry)
110103

111104
/** All lambda parameters with the same name are given the same superscript as
112-
* long as their corresponding binder has been printed.
113-
* See tests/neg/lambda-rename.scala for test cases.
105+
* long as their corresponding binders have the same parameter name lists.
106+
* This avoids spurious distinctions between parameters of mapped lambdas at
107+
* the risk that sometimes we cannot distinguish parameters of distinct functions
108+
* that have the same parameter names. See tests/neg/lambda-rename.scala for test cases.
114109
*/
115110
def sameSuperscript(cur: Recorded, existing: Recorded) =
116111
(cur eq existing) ||
117112
(cur, existing).match
118113
case (cur: ParamRef, existing: ParamRef) =>
119-
(cur.paramName eq existing.paramName) &&
120-
openedLambdas.contains(cur.binder) &&
121-
openedLambdas.contains(existing.binder)
114+
(cur.paramName eq existing.paramName)
115+
&& cur.binder.paramNames == existing.binder.paramNames
122116
case _ =>
123117
false
124118

@@ -266,20 +260,10 @@ object Message:
266260
case _ =>
267261
super.funMiddleText(isContextual, isPure, refs)
268262

269-
override def toTextMethodAsFunction(info: Type, isPure: Boolean, refs: GeneralCaptureSet | Null): Text =
270-
info match
271-
case info: LambdaType =>
272-
seen.openLambda(info)
273-
case _ =>
274-
super.toTextMethodAsFunction(info, isPure, refs)
275-
276263
override def toText(tp: Type): Text =
277264
if !tp.exists || tp.isErroneous then seen.nonSensical = true
278265
tp match
279266
case tp: TypeRef if useSourceModule(tp.symbol) => Str("object ") ~ super.toText(tp)
280-
case tp: LambdaType =>
281-
seen.openLambda(tp)
282-
super.toText(tp)
283267
case _ => super.toText(tp)
284268

285269
override def toText(sym: Symbol): Text =

tests/neg-custom-args/captures/filevar.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
|Found: (f: File^'s1) ->'s2 Unit
55
|Required: (f: File^{l}) => Unit
66
|
7-
|where: => refers to a fresh root capability created in anonymous function of type (using l²: scala.caps.Capability): File^{l²} -> Unit when instantiating expected result type (f: File^{l}) ->{cap} Unit of function literal
7+
|where: => refers to a fresh root capability created in anonymous function of type (using l: scala.caps.Capability): File^{l} -> Unit when instantiating expected result type (f: File^{l}) ->{cap} Unit of function literal
88
|
99
|Note that capability l cannot be included in outer capture set 's1 of parameter f.
1010
16 | val o = Service()

tests/neg-custom-args/captures/i15923.check

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
27 | val leak = withCap(cap => mkId(cap)) // error (was: no error here since type aliases don't box)
33
| ^^^^^^^^^^^^^^^^
44
|Found: (cap: test2.Cap^'s1) ->'s2 [T] => (op: test2.Cap^'s3 ->'s4 T) ->'s5 T
5-
|Required: test2.Cap^{lcap} => [T] => (op²: test2.Cap^'s6 ->'s7 T) ->'s8 T
5+
|Required: test2.Cap^{lcap} => [T] => (op: test2.Cap^'s6 ->'s7 T) ->'s8 T
66
|
7-
|where: => refers to a fresh root capability created in anonymous function of type (using lcap²: scala.caps.Capability): test2.Cap^{lcap²} -> [T] => (op³: test2.Cap^{lcap²} => T) -> T when instantiating expected result type test2.Cap^{lcap} ->{cap²} [T] => (op²: test2.Cap^'s6 ->'s7 T) ->'s8 T of function literal
8-
| op is a reference to a value parameter
9-
| op² is a reference to a value parameter
7+
|where: => refers to a fresh root capability created in anonymous function of type (using lcap: scala.caps.Capability): test2.Cap^{lcap} -> [T] => (op: test2.Cap^{lcap} => T) -> T when instantiating expected result type test2.Cap^{lcap} ->{cap²} [T] => (op: test2.Cap^'s6 ->'s7 T) ->'s8 T of function literal
108
|
119
|Note that capability lcap cannot be included in outer capture set 's1 of parameter cap.
1210
|
@@ -17,7 +15,7 @@
1715
|Found: (cap: Cap^'s9) ->'s10 Id[Cap^'s11]^'s12
1816
|Required: Cap^{lcap} => Id[Cap^'s13]^'s14
1917
|
20-
|where: => refers to a fresh root capability created in anonymous function of type (using lcap²: scala.caps.Capability): Cap^{lcap²} -> Id[Cap] when instantiating expected result type Cap^{lcap} ->{cap²} Id[Cap^'s13]^'s14 of function literal
18+
|where: => refers to a fresh root capability created in anonymous function of type (using lcap: scala.caps.Capability): Cap^{lcap} -> Id[Cap] when instantiating expected result type Cap^{lcap} ->{cap²} Id[Cap^'s13]^'s14 of function literal
2119
|
2220
|Note that capability lcap cannot be included in outer capture set 's9 of parameter cap.
2321
|

0 commit comments

Comments
 (0)