Skip to content

Commit

Permalink
Compute isCompleted together with typeParams for kind-arity check
Browse files Browse the repository at this point in the history
Being complete is a dynamic property. If we take `typeParams`
before being complete they are unusable. But inbetween we might
get completed and suddenly start passing the check. This is why
the problem manifests in the second parameter of `S`.
  • Loading branch information
joroKr21 committed Dec 20, 2020
1 parent 1a4fa66 commit 33bbc2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -5535,18 +5535,17 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
}

def typedAppliedTypeTree(tree: AppliedTypeTree) = {
val tpt = tree.tpt
val args = tree.args
val tpt1 = typed1(tpt, mode | FUNmode | TAPPmode, WildcardType)
def isPoly = tpt1.tpe.isInstanceOf[PolyType]
def isComplete = tpt1.symbol.rawInfo.isComplete
val tpt = tree.tpt
val args = tree.args
val tpt1 = typed1(tpt, mode | FUNmode | TAPPmode, WildcardType)

if (tpt1.isErrorTyped) {
tpt1
} else if (!tpt1.hasSymbolField) {
AppliedTypeNoParametersError(tree, tpt1.tpe)
} else {
val tparams = tpt1.symbol.typeParams
val isComplete = tpt1.symbol.rawInfo.isComplete

if (sameLength(tparams, args)) {
// @M: kind-arity checking is done here and in adapt, full kind-checking is in checkKindBounds (in Infer)
Expand Down Expand Up @@ -5594,6 +5593,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
}
val original = treeCopy.AppliedTypeTree(tree, tpt1, args1)
val result = TypeTree(appliedType(tpt1.tpe, argtypes)) setOriginal original
val isPoly = tpt1.tpe.isInstanceOf[PolyType]
if (isPoly) // did the type application (performed by appliedType) involve an unchecked beta-reduction?
TypeTreeWithDeferredRefCheck() { () =>
// wrap the tree and include the bounds check -- refchecks will perform this check (that the beta reduction was indeed allowed) and unwrap
Expand Down
8 changes: 8 additions & 0 deletions test/files/pos/t12187.scala
@@ -0,0 +1,8 @@
object Test {
trait Foo[S[_[_], _[_]]] extends Bar[S] {
def m[F[_]](x: S[({ type G[A] = Bar[S] })#G, F]): Unit
}
trait Bar[S[_[_], _[_]]] {
def m[F[_]](x: S[({ type G[A] = Bar[S] })#G, F]): Unit
}
}

0 comments on commit 33bbc2a

Please sign in to comment.