Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -657,12 +657,30 @@ object ProtoTypes {
* [](args): resultType, where args are known to be typed
*/
class FunProtoTyped(args: List[tpd.Tree], resultType: Type)(typer: Typer, applyKind: ApplyKind)(using Context)
extends FunProto(args, resultType)(typer, applyKind):
extends FunProto(args, resultType)(typer, applyKind) {
override def typedArgs(norm: (untpd.Tree, Int) => untpd.Tree)(using Context): List[tpd.Tree] = args
override def typedArg(arg: untpd.Tree, formal: Type)(using Context): tpd.Tree = arg.asInstanceOf[tpd.Tree]
override def allArgTypesAreCurrent()(using Context): Boolean = true
override def withContext(ctx: Context): FunProtoTyped = this

override def map(tm: TypeMap)(using Context): FunProtoTyped =
derivedFunProtoTyped(args, tm(resultType), typer)

override def fold[T](x: T, ta: TypeAccumulator[T])(using Context): T =
ta(ta.foldOver(x, typedArgs().tpes), resultType)

def derivedFunProtoTyped(
args: List[tpd.Tree] = this.args,
resultType: Type = this.resultType,
typer: Typer = this.typer): FunProtoTyped =
if (args eq this.args)
&& (resultType eq this.resultType)
&& (typer eq this.typer)
then this
else FunProtoTyped(args, resultType)(typer, applyKind)
}


/** A prototype for implicitly inferred views:
*
* []: argType => resultType
Expand Down Expand Up @@ -1050,10 +1068,7 @@ object ProtoTypes {
case tp => wildApprox(tp, theMap, seen, internal)
arg.withType(argTp))
val resTp = wildApprox(tp.resultType, theMap, seen, internal)
if (args eq tp.args) && (resTp eq tp.resultType) then
tp
else
FunProtoTyped(args, resTp)(ctx.typer, tp.applyKind)
FunProtoTyped(args, resTp)(ctx.typer, tp.applyKind)
case tp: IgnoredProto =>
WildcardType
case _: ThisType | _: BoundType => // default case, inlined for speed
Expand Down
14 changes: 14 additions & 0 deletions tests/neg/i24824.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trait TC[X]
object TC {
given t2[T]: TC[T] = ???
given t1[T]: TC[T] = ???
}
class Seq2[T] {
def sorted(using TC[T]): Seq2[T] = ???
}
extension [T](s: Seq2[T])
def f[G](c: Seq2[G]): Unit = ??? // error // Extension without extension methods
object Crash {
val s: Seq2[Int] = ???
s.sorted.f(Seq2()) // error // ambiguous given instances: both given instance t2 in object TC and given instance t1 in object TC match type TC[Int] of parameter x$1 of method sorted in class Seq2
}
Loading