Skip to content

Commit 91c18e7

Browse files
committed
Generalize isArgPrefixOf
Fixes #11057 We had a case of getting the info of C#F at pattern matching, where `F` as a paremeter of `C`. In this case, no recomputation of the argument via argInfo is needed; the info is the info of `F` directly.
1 parent 5672999 commit 91c18e7

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,15 @@ object Types {
289289
def isFromJavaObject(using Context): Boolean = typeSymbol eq defn.FromJavaObjectSymbol
290290

291291
/** True iff `symd` is a denotation of a class type parameter and the reference
292-
* `<this> . <symd>` is an actual argument reference, i.e. `this` is different
293-
* from the ThisType of `symd`'s owner.
292+
* `<pre> . <symd>` is an actual argument reference, i.e. `pre` is not the
293+
* ThisType of `symd`'s owner, or a reference to `symd`'s owner.'
294294
*/
295295
def isArgPrefixOf(symd: SymDenotation)(using Context): Boolean =
296296
symd.exists && !symd.owner.is(Package) && // Early exit if possible because the next check would force SymbolLoaders
297297
symd.isAllOf(ClassTypeParam) && {
298298
this match {
299299
case tp: ThisType => tp.cls ne symd.owner
300+
case tp: TypeRef => tp.symbol ne symd.owner
300301
case _ => true
301302
}
302303
}
@@ -2212,7 +2213,8 @@ object Types {
22122213
throw new TypeError(
22132214
i"""bad parameter reference $this at ${ctx.phase}
22142215
|the parameter is ${param.showLocated} but the prefix $prefix
2215-
|does not define any corresponding arguments.""")
2216+
|does not define any corresponding arguments.
2217+
|idx = $idx, args = $args""")
22162218
NoDenotation
22172219
}
22182220
}

tests/pos/i11057.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
object data {
2+
3+
trait OfType[T]
4+
case object IntT extends OfType[Int]
5+
case object DoubleT extends OfType[Double]
6+
case object FloatT extends OfType[Float]
7+
8+
type DSeq[X] = scala.collection.immutable.AbstractSeq[X]
9+
10+
case class ColumnName[T](n:String, t: OfType[T])
11+
case class Column[T,F[_]<:DSeq[_]](n:F[T], of: ColumnName[T])
12+
}
13+
14+
def min4[T,F[_]<:data.DSeq[T]](col: data.Column[T,F])(using Ordering[T]): T = {
15+
col match {
16+
case c:data.Column[Int,_] => c.n.min[T](Ordering[T])
17+
case _:data.Column[Double,_] => ???
18+
case _:data.Column[Float,_] => ???
19+
}
20+
}

0 commit comments

Comments
 (0)