Skip to content

Fix isAbsType prediction in TreeUnpickler #14861

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

Merged
merged 1 commit into from
Apr 14, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4206,7 +4206,7 @@ object Types {
* This is the case if tycon is higher-kinded. This means
* it is a subtype of a hk-lambda, but not a match alias.
* (normal parameterized aliases are removed in `appliedTo`).
* Applications of hgher-kinded type constructors to wildcard arguments
* Applications of higher-kinded type constructors to wildcard arguments
* are equivalent to existential types, which are not supported.
*/
def isUnreducibleWild(using Context): Boolean =
Expand Down
24 changes: 18 additions & 6 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -500,16 +500,28 @@ class TreeUnpickler(reader: TastyReader,
flags
}

def isAbstractType(ttag: Int)(using Context): Boolean = nextUnsharedTag match {
def isAbstractType(name: Name)(using Context): Boolean = nextByte match
case SHAREDtype =>
val lookAhead = fork
lookAhead.reader.readByte()
val sharedReader = forkAt(lookAhead.reader.readAddr())
sharedReader.isAbstractType(name)
case LAMBDAtpt =>
val rdr = fork
rdr.reader.readByte() // tag
rdr.reader.readNat() // length
rdr.skipParams() // tparams
rdr.isAbstractType(rdr.nextUnsharedTag)
case TYPEBOUNDS | TYPEBOUNDStpt => true
rdr.isAbstractType(name)
case TYPEBOUNDS =>
val rdr = fork
rdr.reader.readByte() // tag
val end = rdr.reader.readEnd()
rdr.skipTree() // alias, or lower bound
val res = !rdr.nothingButMods(end)
//if !res then println(i"NOT ABSTRACT $name, ${rdr.reader.nextByte}")
res
case TYPEBOUNDStpt => true
case _ => false
}

/** Create symbol of definition node and enter in symAtAddr map
* @return the created symbol
Expand Down Expand Up @@ -554,15 +566,15 @@ class TreeUnpickler(reader: TastyReader,
if (tag == TYPEDEF || tag == TYPEPARAM) name = name.toTypeName
skipParams()
val ttag = nextUnsharedTag
val isAbsType = isAbstractType(ttag)
val isAbsType = isAbstractType(name)
val isClass = ttag == TEMPLATE
val templateStart = currentAddr
skipTree() // tpt
val rhsStart = currentAddr
val rhsIsEmpty = nothingButMods(end)
if (!rhsIsEmpty) skipTree()
val (givenFlags, annotFns, privateWithin) = readModifiers(end)
pickling.println(i"creating symbol $name at $start with flags $givenFlags")
pickling.println(i"creating symbol $name at $start with flags ${givenFlags.flagsString}, isAbsType = $isAbsType, $ttag")
val flags = normalizeFlags(tag, givenFlags, name, isAbsType, rhsIsEmpty)
def adjustIfModule(completer: LazyType) =
if (flags.is(Module)) adjustModuleCompleter(completer, name) else completer
Expand Down
3 changes: 3 additions & 0 deletions tests/pos/i14858/A_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import p.*

type NAME2 = C[?]
10 changes: 10 additions & 0 deletions tests/pos/i14858/M_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package p

object M {
class C[N]()
}

export M.*

type CC[N] = M.C[N]
type CCC = M.C[Int]