Skip to content

Commit 399ba70

Browse files
committed
Refine rules when context bound evidence is tracked
Exclude synthetic, unnamed context bound evidence parameters.
1 parent d5f089d commit 399ba70

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,18 +1862,20 @@ class Namer { typer: Typer =>
18621862
sym.setParamss(paramSymss)
18631863

18641864
/** Set every context bound evidence parameter of a class to be tracked,
1865-
* provided it has a type that has an abstract type member. Reset private
1866-
* and local flags so that the parameter becomes a `val`. Do the same for all
1867-
* context bound evidence parameters of a `given` class. This is because
1868-
* in Desugar.addParamRefinements we create refinements for these parameters
1869-
* in the result type of the implicit access method.
1865+
* provided it has a type that has an abstract type member and the parameter's
1866+
* name is not a synthetic, unaddressable name. Reset private and local flags
1867+
* so that the parameter becomes a `val`. Do the same for all context bound
1868+
* evidence parameters of a `given` class. This is because in Desugar.addParamRefinements
1869+
* we create refinements for these parameters in the result type of the implicit
1870+
* access method.
18701871
*/
18711872
def setTracked(param: ValDef): Unit =
18721873
val sym = symbolOfTree(param)
18731874
sym.maybeOwner.maybeOwner.infoOrCompleter match
18741875
case info: TempClassInfo =>
18751876
if !sym.is(Tracked)
18761877
&& param.hasAttachment(ContextBoundParam)
1878+
&& !param.name.is(ContextBoundParamName)
18771879
&& (sym.info.memberNames(abstractTypeNameFilter).nonEmpty
18781880
|| sym.maybeOwner.maybeOwner.is(Given))
18791881
then

tests/pos/parsercombinators-new-syntax.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import collection.mutable
33

44
/// A parser combinator.
55
trait Combinator:
6-
76
type Self
87
type Input
98
type Result
@@ -13,21 +12,22 @@ trait Combinator:
1312
def parse(in: Input): Option[Result]
1413
end Combinator
1514

16-
case class Apply[C, E](action: C => Option[E])
15+
case class Apply[I, R](action: I => Option[R])
1716
case class Combine[A, B](first: A, second: B)
1817

1918
given [I, R] => Apply[I, R] is Combinator:
2019
type Input = I
2120
type Result = R
22-
extension (self: Self)
21+
extension (self: Apply[I, R])
2322
def parse(in: I): Option[R] = self.action(in)
2423

2524
given [A: Combinator, B: Combinator { type Input = A.Input }]
2625
=> Combine[A, B] is Combinator:
2726
type Input = A.Input
2827
type Result = (A.Result, B.Result)
29-
extension (self: Self)
30-
def parse(in: Input): Option[Result] = ???
28+
extension (self: Combine[A, B])
29+
def parse(in: Input): Option[Result] =
30+
for x <- self.first.parse(in); y <- self.second.parse(in) yield (x, y)
3131

3232
extension [A] (buf: mutable.ListBuffer[A]) def popFirst() =
3333
if buf.isEmpty then None

0 commit comments

Comments
 (0)