Skip to content

Commit 0254b1b

Browse files
authored
Merge pull request #7905 from dotty-staging/fix-#7868
Fix #7868: Normalize type parameter in ValueOf
2 parents 3951e2e + e094ced commit 0254b1b

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ trait Implicits { self: Typer =>
861861

862862
formal.argInfos match {
863863
case arg :: Nil =>
864-
fullyDefinedType(arg.dealias, "ValueOf argument", span) match {
864+
fullyDefinedType(arg.dealias, "ValueOf argument", span).normalized match {
865865
case ConstantType(c: Constant) =>
866866
success(Literal(c))
867867
case TypeRef(_, sym) if sym == defn.UnitClass =>

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typelevel0.scala
2222
matchtype.scala
2323
6322.scala
2424
i7087.scala
25+
i7868.scala
2526

2627
# Opaque type
2728
i5720.scala

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ t8905
2222
t10889
2323
macros-in-same-project1
2424
i5257.scala
25+
i7868.scala
2526
enum-java

tests/pos/i7868.scala

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import scala.compiletime._
2+
3+
final case class Coproduct[+Set, +Value, Index <: Int](value: Value & Set, index: Index)
4+
5+
object Coproduct {
6+
opaque type +:[+A, +B] = A | B
7+
8+
trait At[+Set, -Value, Index <: Int] {
9+
def cast: Value <:< Set
10+
}
11+
12+
object At {
13+
14+
given atHead[Head, Tail]: At[Head +: Tail, Head, 0] {
15+
def cast: Head <:< Head +: Tail = summon[Head <:< Head +: Tail]
16+
}
17+
18+
given atTail[Head, Tail, Value, NextIndex <: Int](given atNext: At[Tail, Value, NextIndex]): At[Head +: Tail, Value, S[NextIndex]] {
19+
val cast: Value <:< Head +: Tail = atNext.cast
20+
}
21+
22+
given [A](given A): (() => A)= { () => summon[A]}
23+
}
24+
25+
def upCast[A, B](a: A)(given erased evidence: (A <:< B)): B = a.asInstanceOf[B]
26+
27+
def from[Set, Value, Index <: Int](value: Value)(given erased at: At[Set, Value, Index]): (given ValueOf[Index]) => Coproduct[Set, Value, Index] = {
28+
Coproduct[Set, Value, Index](upCast(value: Value)(given at.cast.liftCo[[+X] =>> Value & X]), valueOf[Index])
29+
}
30+
31+
}
32+
33+
object Test extends App {
34+
import Coproduct._
35+
36+
// Error: No singleton value available for scala.compiletime.S[scala.compiletime.S[(0 : Int)]].
37+
val c = from[Set = Int +: String +: Seq[Double] +: Nothing](Nil)
38+
}

tests/run/i7868.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.compiletime.S
2+
3+
object Test extends App {
4+
def plusOne[I <: Int](given x: ValueOf[S[I]]): S[I] = x.value
5+
def plusTwo[I <: Int](given x: ValueOf[S[S[I]]]): S[S[I]] = x.value
6+
assert(plusOne[0] == 1)
7+
assert(plusTwo[0] == 2)
8+
}

0 commit comments

Comments
 (0)