Skip to content

Commit 55bac27

Browse files
committed
Fixes to allow for generic transparent type devfinitions
1 parent 486f412 commit 55bac27

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
578578
loop(fn, targss, args :: argss)
579579
case TypeApply(fn, targs) =>
580580
loop(fn, targs ::: targss, argss)
581+
case AppliedTypeTree(fn, targs) =>
582+
loop(fn, targs ::: targss, argss)
581583
case _ =>
582584
(tree, targss, argss)
583585
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ object Types {
995995

996996
/** If this type is a typeref with a type lambda as alias or upper bound, widen to the lambda */
997997
final def toLambda(implicit ctx: Context): Type = widen match {
998-
case tp: TypeRef if tp.info.hiBound.isInstanceOf[LambdaType] => tp.info.hiBound
998+
case tp: TypeProxy if tp.superType.isInstanceOf[LambdaType] => tp.superType
999999
case tp => tp
10001000
}
10011001

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
255255
matchArgs(orderedArgs, methType.paramInfos, 0)
256256
case _ =>
257257
if (methType.isError) ok = false
258-
else fail(s"$methString does not take parameters?")
258+
else fail(s"$methString does not take parameters")
259259
}
260260

261261
/** The application was successful */
@@ -691,7 +691,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
691691

692692
def realApply(implicit ctx: Context): Tree = track("realApply") {
693693
val originalProto = new FunProto(tree.args, IgnoredProto(pt), this)(argCtx(tree))
694-
val fun1 = typedExpr(tree.fun, originalProto)
694+
val fun1 = typed(tree.fun, originalProto)(ctx.retractMode(Mode.Pattern))
695695

696696
// Warning: The following lines are dirty and fragile. We record that auto-tupling was demanded as
697697
// a side effect in adapt. If it was, we assume the tupled proto-type in the rest of the application,

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,13 @@ trait NamerContextOps { this: Context =>
147147
}
148148
else HKTermLambda.fromParams(params, resultType)
149149
}
150-
if (typeParams.nonEmpty) PolyType.fromParams(typeParams, monotpe)
151-
else if (valueParamss.isEmpty) ExprType(monotpe)
152-
else monotpe
150+
if (sym.isTerm)
151+
if (typeParams.nonEmpty) PolyType.fromParams(typeParams, monotpe)
152+
else if (valueParamss.isEmpty) ExprType(monotpe)
153+
else monotpe
154+
else
155+
if (typeParams.nonEmpty) HKTypeLambda.fromParams(typeParams, monotpe)
156+
else monotpe
153157
}
154158

155159
/** Add moduleClass or sourceModule functionality to completer

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,14 +2158,12 @@ class Typer extends Namer
21582158
false
21592159
}
21602160

2161-
def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match {
2162-
case _: MethodOrPoly =>
2161+
def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp.toLambda match {
2162+
case _: LambdaType =>
21632163
if (pt.args.lengthCompare(1) > 0 && isUnary(wtp) && ctx.canAutoTuple)
21642164
adapt(tree, pt.tupled, locked)
21652165
else
21662166
tree
2167-
case wtp: TypeRef if wtp.underlying.hiBound.isInstanceOf[HKLambda] =>
2168-
tree
21692167
case _ => tryInsertApplyOrImplicit(tree, pt, locked) {
21702168
errorTree(tree, MethodDoesNotTakeParameters(tree))
21712169
}
@@ -2489,8 +2487,9 @@ class Typer extends Namer
24892487
}
24902488

24912489
def adaptType(tp: Type): Tree = {
2490+
val isApplied = pt `eq` AnyTypeConstructorProto
24922491
val tree1 =
2493-
if ((pt eq AnyTypeConstructorProto) || tp.typeParamSymbols.isEmpty) tree
2492+
if (isApplied || tp.typeParamSymbols.isEmpty) tree
24942493
else {
24952494
val tp1 =
24962495
if (ctx.compilationUnit.isJava)
@@ -2507,7 +2506,7 @@ class Typer extends Namer
25072506
case pt: TypeBounds if ctx.mode `is` Mode.Type => pt `contains` tree1.tpe
25082507
case _ => tree1.tpe <:< pt
25092508
}
2510-
if (Inliner.isInlineable(tree.symbol))
2509+
if (!isApplied && Inliner.isInlineable(tree.symbol))
25112510
readaptSimplified {
25122511
Inliner.inlineCall(tree, pt) match {
25132512
case inlined: Inlined => TypeTree(inlined.tpe).withPos(tree.pos)

tests/run/typelevel2.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,15 @@ object Test extends App {
3434
def ii: Int = 2
3535
def nn: ToNat(ii) = S(S(Z)) // no expansion possible, since `ii` is of type `Int`.
3636
val ii1: Int = nn.toInt
37+
38+
type nth[F[_], T](n: Int) =
39+
if n == 0 then T
40+
else F[nth[F, T](n - 1)]
41+
42+
val nth0: nth[List, Int](0) = 2
43+
val nth1: nth[Option, String](1) = Some("hi")
44+
val nth3: nth[Seq, Boolean](3) = Seq(Seq(Seq(true, false)))
45+
val nth0a: Int = nth0
46+
val nth1a: Option[String] = nth1
47+
val nth3a: Seq[Seq[Seq[Boolean]]] = nth3
3748
}

0 commit comments

Comments
 (0)