The TypeMap handling the asSeenFrom in more complicated cases
An argument bounds violation is a triple consisting of
An argument bounds violation is a triple consisting of
Approximate union type by intersection of its dominators.
Approximate union type by intersection of its dominators. See Type#approximateUnion for an explanation.
The type tp
as seen from prefix pre
and owner cls
.
The type tp
as seen from prefix pre
and owner cls
. See the spec
for what this means. Called very often, so the code is optimized heavily.
A tricky aspect is what to do with unstable prefixes. E.g. say we have a class
class C { type T; def f(x: T): T }
and an expression e
of type C
. Then computing the type of e.f
leads
to the query asSeenFrom(C
, (x: T)T
). What should its result be? The
naive answer (x: C#T)C#T
is incorrect given that we treat C#T
as the existential
exists(c: C)c.T
. What we need to do instead is to skolemize the existential. So
the answer would be (x: c.T)c.T
for some (unknown) value c
of type C
.
c.T
is expressed in the compiler as a skolem type Skolem(C)
.
Now, skolemization is messy and expensive, so we want to do it only if we absolutely must. Also, skolemizing immediately would mean that asSeenFrom was no longer idempotent - each call would return a type with a different skolem. Instead we produce an annotated type that marks the prefix as unsafe:
(x: (C @ UnsafeNonvariant)#T)C#T
We also set a global state flag unsafeNonvariant
to the current run.
When typing a Select node, typer will check that flag, and if it
points to the current run will scan the result type of the select for
The list of violations where arguments are not within bounds.
The list of violations where arguments are not within bounds.
The arguments
The list of type bounds
A function that maps a bound type and the list of argument types to a resulting type. Needed to handle bounds that refer to other bounds.
Is auto-tupling enabled?
Approximate a type tp
with a type that does not contain skolem types.
Is feature
enabled in class owner
?
This is the case if one of the following two alternatives holds:
Is feature
enabled in class owner
?
This is the case if one of the following two alternatives holds:
import owner.feature
(the feature may be bunched with others, or renamed, but wildcard imports don't count).
2. The feature is enabled by a compiler option
where <prefix> is the full name of the owner followed by a "." minus the prefix "dotty.language.".
If we have member definitions
If we have member definitions
type argSym v= from type from v= to
where the variances of both alias are the same, then enter a new definition
type argSym v= to
unless a definition for argSym
already exists in the current scope.
If tpe
is of the form p.x
where p
refers to a package
but x
is not owned by a package, expand it to
If tpe
is of the form p.x
where p
refers to a package
but x
is not owned by a package, expand it to
p.package.x
Normalize a list of parent types of class cls
that may contain refinements
to a list of typerefs referring to classes, by converting all refinements to member
definitions in scope decls
.
Normalize a list of parent types of class cls
that may contain refinements
to a list of typerefs referring to classes, by converting all refinements to member
definitions in scope decls
. Can add members to decls
as a side-effect.
Implementation of Types#simplified