Skip to content

Commit 59ab35e

Browse files
committed
Refactor instantiate
This if for better understandability only since it avoids the deeply nested return. Also, add a new test showing how to deal with tracked parameters in typeclass arguments.
1 parent c9781fa commit 59ab35e

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,8 +4946,7 @@ object Types extends TypeUtils {
49464946
* is also a singleton type.
49474947
*/
49484948
def instantiate(fromBelow: Boolean)(using Context): Type =
4949-
val tp = typeToInstantiateWith(fromBelow)
4950-
instantiateWith(tp)
4949+
instantiateWith(typeToInstantiateWith(fromBelow))
49514950

49524951
/** Widen unions when instantiating this variable in the current context? */
49534952
def widenUnions(using Context): Boolean = !ctx.typerState.constraint.isHard(this)

tests/pos/ord-over-tracked.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import language.experimental.modularity
2+
3+
trait Ord[T]:
4+
def lt(x: T, y: T): Boolean
5+
6+
given Ord[Int] = ???
7+
8+
case class D(tracked val x: Int)
9+
given [T <: D]: Ord[T] = (a, b) => a.x < b.x
10+
11+
def mySort[T: Ord](x: Array[T]): Array[T] = ???
12+
13+
def test =
14+
val arr = Array(D(1))
15+
val arr1 = mySort(arr) // error: no given instance of type Ord[D{val x: (1 : Int)}]

0 commit comments

Comments
 (0)