-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4557: Handle untpd.New with HKTypeLambda #4798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
This still fails: class A[X]
type T[X, Y] = A[X]
type Foo[X, Y] = T[X, Y]
class B extends Foo[Int, Int] This now crashes: class A[X]
type Foo[X, Y] = [Z] => A[X]
class B extends Foo[Int, Int] |
To make the upper one work, I changed code to reduce a type recursively. If the result of reduction is AppliedType and its tycon is dealiased to HKTypeLambda, the compiler will reduce the type again. To prevent crash, the compiler checks whether the reduced type is ValueType. If it is not, then the reduced one cannot be a prefix of Select, so that the compiler uses the original type. |
This looks pretty good to me, tho probably an expert should review the new fixes.
object Test {
class A[X]
type T[X, Y] = A[X]
type Bar[X, Y] = Foo[X, Y]
type Foo[X, Y] = Bar[X, Y]
class B extends Foo[Int, Int]
} object Test {
class A[X]
type T[X, Y] = A[X]
type Bar[X, Y] = Foo[X, Y]
type Foo[X, Y] = Bar[X, Y]
class B extends Foo[Int, Int]
} Output — note that
When you're done with these concern, we'll assign Odersky for the final review. |
I found that the types of parents are calcualted already in I thought that the code can be more simplified as in https://github.com/Medowhill/dotty/commit/6c938a9cb40745b70d25d1cb9bd79025bfacb698 but it failed on tests
I believe that this behavior does not affect actual execution. However, since the tests fail, I do not include the simplified version in this PR. When I simplified the pattern from
I'll report this behavior as a seperate issue with a simpler code example. |
I applied the change of https://github.com/Medowhill/dotty/commit/6c938a9cb40745b70d25d1cb9bd79025bfacb698 and removed |
if (tpt1.isInstanceOf[AppliedTypeTree] && !tp.isInstanceOf[ValueType]) { | ||
ctx.error(ex"$tp is not a class type", tpt.pos) | ||
tp = defn.ObjectType | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this test if you do that:
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala
index 8a08be37b..3251f2735 100644
--- a/compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -516,7 +516,8 @@ class Typer extends Namer
case TypeApplications.EtaExpansion(tycon) => tpt1 = tpt1.withType(tycon)
case _ =>
}
- checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true)
+ if (checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true) eq defn.ObjectType)
+ tpt1 = TypeTree(defn.ObjectType)
tpt1 match {
case AppliedTypeTree(_, targs) =>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked that it passed all the tests. I've just pushed it. Thank you!
@@ -10,6 +10,7 @@ import util.Property | |||
import language.higherKinds | |||
import collection.mutable.ListBuffer | |||
import reflect.ClassTag | |||
import annotation.tailrec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
Can you squash the commits of this PR |
case TypedSplice(tpt1: tpd.Tree) => | ||
val tycon = tpt1.tpe.typeConstructor | ||
val argTypes = tpt1.tpe.argTypesLo | ||
var tp = tpt1.tpe.dealias |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be a val
@@ -516,7 +516,8 @@ class Typer extends Namer | |||
case TypeApplications.EtaExpansion(tycon) => tpt1 = tpt1.withType(tycon) | |||
case _ => | |||
} | |||
checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true) | |||
if (checkClassType(tpt1.tpe, tpt1.pos, traitReq = false, stablePrefixReq = true) eq defn.ObjectType) | |||
tpt1 = TypeTree(defn.ObjectType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, creating a new tree like this will not set its position and so on, unlike tpt1 = tpt1.withType(defn.ObjectType)
(like here) or TypeTree(defn.ObjectType) withPos tpt.pos
(like in New
). OTOH, this isn't a tree the user wrote. And maybe the point of using defn.ObjectType
is to hope we get no other error here?
What makes more sense @allanrenucci?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tpt1 = TypeTree(defn.ObjectType).withPos(tpt1.pos)
I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Medowhill Does this need addressing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change it to tpt1 = TypeTree(defn.ObjectType).withPos(tpt1.pos)
. Thank you!
@Medowhill FWIW, the over-eager dealiasing has a separate issue (#4565). |
No description provided.