Skip to content
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

Use a new prefixDirect in checkKindBounds0 #9404

Merged
merged 1 commit into from Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/reflect/scala/reflect/internal/Kinds.scala
Expand Up @@ -219,14 +219,15 @@ trait Kinds {
// Prevent WildcardType from causing kind errors, as typevars may be higher-order
if (targ == WildcardType) Nil else {
// NOTE: *not* targ.typeSymbol, which normalizes
val targSym = targ.typeSymbolDirect
// force symbol load for #4205
targSym.info
// force initialize symbol for scala/bug#4205
val targSym = targ.typeSymbolDirect.initialize
// NOTE: *not* targ.prefix, which normalizes
val targPre = targ.prefixDirect
// @M must use the typeParams of the *type* targ, not of the *symbol* of targ!!
val tparamsHO = targ.typeParams
if (targ.isHigherKinded || tparam.typeParams.nonEmpty) {
val kindErrors = checkKindBoundsHK(
tparamsHO, targSym, targ.prefix, targSym.owner,
tparamsHO, targSym, targPre, targSym.owner,
tparam, tparam.owner, tparam.typeParams, tparamsHO
)
if (kindErrors.isEmpty) Nil else {
Expand Down
8 changes: 8 additions & 0 deletions src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -163,6 +163,7 @@ trait Types
override def upperBound = underlying.upperBound
override def parents = underlying.parents
override def prefix = underlying.prefix
override def prefixDirect = underlying.prefixDirect
override def decls = underlying.decls
override def baseType(clazz: Symbol) = underlying.baseType(clazz)
override def baseTypeSeq = underlying.baseTypeSeq
Expand Down Expand Up @@ -425,6 +426,12 @@ trait Types
* NoType for all other types. */
def prefix: Type = NoType

/** The prefix ''directly'' associated with the type.
* In other words, no normalization is performed: if this is an alias type,
* the prefix returned is that of the alias, not the underlying type.
*/
def prefixDirect: Type = prefix

/** A chain of all typeref or singletype prefixes of this type, longest first.
* (Only used from safeToString.)
*/
Expand Down Expand Up @@ -2580,6 +2587,7 @@ trait Types

override def baseTypeSeqDepth = baseTypeSeq.maxDepth
override def prefix = pre
override def prefixDirect = pre
override def termSymbol = super.termSymbol
override def termSymbolDirect = super.termSymbol
override def typeArgs = args
Expand Down
23 changes: 23 additions & 0 deletions test/files/pos/t12142.scala → test/files/pos/hk-paths.scala
@@ -1,4 +1,5 @@
object Test {
// scala/bug#12142
trait Bounds {
type Upper <: Bounds
}
Expand Down Expand Up @@ -35,4 +36,26 @@ object Test {
x.expr.applyTo[({ type E[B >: A <: U] = fun.Super[B] })#E]
x.expr.applyTo[fun.Super]
}

// scala/bug#10186
trait Foo {
type A
type F[_ <: A]
}

def noop[A, F[_ <: A]]: Unit = ()
def f(foo: Foo): Unit = noop[foo.A, foo.F]

// scala/bug#9625
trait `* -> *`[F[_]]

trait Bar {
type Qux[A]
implicit val `* -> *`: `* -> *`[Qux]
}

def foo(bar: Bar): `* -> *`[bar.Qux] = {
import bar._
implicitly[`* -> *`[bar.Qux]]
}
}
13 changes: 13 additions & 0 deletions test/files/pos/t9337.scala
@@ -0,0 +1,13 @@
object Test {
trait TypePreservingFn[T[X <: T[X]]]
trait Validator[T, This <: Validator[T,This]]

trait Foo[T] {
type V[This <: Validator[T, This]] = Validator[T, This]
val f: TypePreservingFn[V] = ???
}

class Bar[T] extends Foo[T] {
val g: TypePreservingFn[V] = ???
}
}