Skip to content

Commit ab7a521

Browse files
committed
Fix typing of generated context bound refinements
Avoid accidental binding to self # Conflicts: # compiler/src/dotty/tools/dotc/typer/Typer.scala
1 parent abca391 commit ab7a521

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
22112211
if tycon.tpe.typeParams.nonEmpty then
22122212
typed(untpd.AppliedTypeTree(tyconSplice, tparam :: Nil))
22132213
else if Feature.enabled(modularity) && tycon.tpe.member(tpnme.Self).symbol.isAbstractType then
2214-
typed(untpd.RefinedTypeTree(tyconSplice, List(untpd.TypeDef(tpnme.Self, tparam))))
2214+
val tparamSplice = untpd.TypedSplice(typedExpr(tparam))
2215+
typed(untpd.RefinedTypeTree(tyconSplice, List(untpd.TypeDef(tpnme.Self, tparamSplice))))
22152216
else
22162217
errorTree(tree,
22172218
em"""Illegal context bound: ${tycon.tpe} does not take type parameters and

tests/pos/hylolib-extract.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
//> using options -language:experimental.modularity -source future
22
package hylotest
33

4-
trait Value[Self]
4+
trait Value:
5+
type Self
6+
extension (self: Self) def eq(other: Self): Boolean
57

68
/** A collection of elements accessible by their position. */
7-
trait Collection[Self]:
9+
trait Collection:
10+
type Self
811

912
/** The type of the elements in the collection. */
1013
type Element: Value
1114

1215
class BitArray
1316

14-
given Value[Boolean] {}
17+
given Boolean is Value:
18+
extension (self: Self) def eq(other: Self): Boolean =
19+
self == other
1520

16-
given Collection[BitArray] with
21+
given BitArray is Collection:
1722
type Element = Boolean
23+
24+
extension [Self: Value](self: Self)
25+
def neq(other: Self): Boolean = !self.eq(other)

0 commit comments

Comments
 (0)