@@ -1124,21 +1124,16 @@ object Types {
1124
1124
}
1125
1125
1126
1126
/** The type <this . name> , reduced if possible */
1127
- def select (name : Name )(implicit ctx : Context ): Type = name match {
1128
- case name : TermName => TermRef (this , name)
1129
- case name : TypeName => TypeRef (this , name).reduceProjection
1130
- }
1127
+ def select (name : Name )(implicit ctx : Context ): Type =
1128
+ NamedType (this , name).reduceProjection
1131
1129
1132
1130
/** The type <this . name> , reduced if possible, with given denotation if unreduced */
1133
- def select (name : Name , denot : Denotation )(implicit ctx : Context ): Type = name match {
1134
- case name : TermName => TermRef (this , name, denot)
1135
- case name : TypeName => TypeRef (this , name, denot).reduceProjection
1136
- }
1131
+ def select (name : Name , denot : Denotation )(implicit ctx : Context ): Type =
1132
+ NamedType (this , name, denot).reduceProjection
1137
1133
1138
- /** The type <this . name> with given symbol , reduced if possible */
1134
+ /** The type <this . name> with either `sym` or its signed name as designator , reduced if possible */
1139
1135
def select (sym : Symbol )(implicit ctx : Context ): Type =
1140
- if (sym.isTerm) TermRef .withSym(this , sym.asTerm)
1141
- else TypeRef .withSym(this , sym.asType).reduceProjection
1136
+ NamedType (this , sym, sym.name).reduceProjection
1142
1137
1143
1138
// ----- Access to parts --------------------------------------------
1144
1139
@@ -1762,10 +1757,12 @@ object Types {
1762
1757
* provided `U` does not refer with a RecThis to the
1763
1758
* refinement type `T { X = U; ... }`
1764
1759
*/
1765
- def reduceProjection (implicit ctx : Context ): Type = {
1766
- val reduced = prefix.lookupRefined(name)
1767
- if (reduced.exists) reduced else this
1768
- }
1760
+ def reduceProjection (implicit ctx : Context ): Type =
1761
+ if (isType) {
1762
+ val reduced = prefix.lookupRefined(name)
1763
+ if (reduced.exists) reduced else this
1764
+ }
1765
+ else this
1769
1766
1770
1767
def symbol (implicit ctx : Context ): Symbol =
1771
1768
if (checkedPeriod == ctx.period ||
@@ -2033,103 +2030,82 @@ object Types {
2033
2030
def apply (prefix : Type , designator : Name , denot : Denotation )(implicit ctx : Context ) =
2034
2031
if (designator.isTermName) TermRef (prefix, designator.asTermName, denot)
2035
2032
else TypeRef (prefix, designator.asTypeName, denot)
2036
- def withSymAndName (prefix : Type , sym : Symbol , name : Name )(implicit ctx : Context ): NamedType =
2037
- if (sym.isType) TypeRef .withSymAndName (prefix, sym.asType, name.asTypeName)
2038
- else TermRef .withSymAndName (prefix, sym.asTerm, name.asTermName)
2033
+ def apply (prefix : Type , sym : Symbol , name : Name )(implicit ctx : Context ): NamedType =
2034
+ if (sym.isType) TypeRef .apply (prefix, sym.asType, name.asTypeName)
2035
+ else TermRef .apply (prefix, sym.asTerm, name.asTermName)
2039
2036
}
2040
2037
2041
2038
object TermRef {
2042
2039
2043
- private def symbolicRefs (implicit ctx : Context ) = ctx.phase.symbolicRefs
2044
-
2045
2040
/** Create term ref with given name, without specifying a signature.
2046
2041
* Its meaning is the (potentially multi-) denotation of the member(s)
2047
2042
* of prefix with given name.
2048
2043
*/
2049
2044
def apply (prefix : Type , designator : TermDesignator )(implicit ctx : Context ): TermRef =
2050
2045
ctx.uniqueNamedTypes.enterIfNew(prefix, designator, isTerm = true ).asInstanceOf [TermRef ]
2051
2046
2052
- /** Create term ref referring to given symbol, taking the signature
2053
- * from the symbol if it is completed, or creating a term ref without
2054
- * signature, if symbol is not yet completed.
2047
+ /** Create a term ref referring to given symbol with given name.
2048
+ * This is similar to TermRef(Type, Symbol), except:
2049
+ * (1) the symbol might not yet have a denotation, so the name needs to be given explicitly.
2050
+ * (2) the designator of the TermRef is either the symbol or its name & unforced signature.
2055
2051
*/
2056
- def withSym (prefix : Type , sym : TermSymbol )(implicit ctx : Context ): TermRef =
2057
- withSymAndName(prefix, sym, sym.name)
2052
+ def apply (prefix : Type , sym : TermSymbol , name : TermName )(implicit ctx : Context ): TermRef =
2053
+ if ((prefix eq NoPrefix ) || sym.isReferencedSymbolically)
2054
+ apply(prefix, sym)
2055
+ else
2056
+ withSig(prefix, name.asTermName, sym.unforcedSignature).withSym(sym)
2058
2057
2059
2058
/** Create term ref to given initial denotation, taking the signature
2060
2059
* from the denotation if it is completed, or creating a term ref without
2061
2060
* signature, if denotation is not yet completed.
2062
2061
*/
2063
2062
def apply (prefix : Type , designator : TermName , denot : Denotation )(implicit ctx : Context ): TermRef = {
2064
- if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically || symbolicRefs )
2065
- withSym (prefix, denot.symbol.asTerm)
2063
+ if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically)
2064
+ apply (prefix, denot.symbol.asTerm)
2066
2065
else denot match {
2067
2066
case denot : SymDenotation if denot.isCompleted => withSig(prefix, designator, denot.signature)
2068
2067
case _ => apply(prefix, designator)
2069
2068
}
2070
2069
} withDenot denot
2071
2070
2072
- /** Create a term ref referring to given symbol with given name, taking the signature
2073
- * from the symbol if it is completed, or creating a term ref without
2074
- * signature, if symbol is not yet completed. This is very similar to TermRef(Type, Symbol),
2075
- * except for two differences:
2076
- * (1) The symbol might not yet have a denotation, so the name needs to be given explicitly.
2077
- * (2) The name in the term ref need not be the same as the name of the Symbol.
2078
- */
2079
- def withSymAndName (prefix : Type , sym : TermSymbol , name : TermName )(implicit ctx : Context ): TermRef =
2080
- if ((prefix eq NoPrefix ) || sym.isReferencedSymbolically|| symbolicRefs)
2081
- apply(prefix, sym)
2082
- else if (sym.defRunId != NoRunId && sym.isCompleted)
2083
- withSig(prefix, name, sym.signature).withSym(sym)
2084
- // Linker note:
2085
- // this is problematic, as withSig method could return a hash-consed refference
2086
- // that could have symbol already set making withSym trigger a double-binding error
2087
- // ./tests/run/absoverride.scala demonstates this
2088
- else
2089
- withSig(prefix, name, Signature .NotAMethod ).withSym(sym)
2090
-
2091
2071
/** Create a term ref to given symbol, taking the signature from the symbol
2092
2072
* (which must be completed).
2093
2073
*/
2094
2074
def withSig (prefix : Type , sym : TermSymbol )(implicit ctx : Context ): TermRef =
2095
- if ((prefix eq NoPrefix ) || sym.isReferencedSymbolically || symbolicRefs ) apply(prefix, sym)
2075
+ if ((prefix eq NoPrefix ) || sym.isReferencedSymbolically) apply(prefix, sym)
2096
2076
else withSig(prefix, sym.name, sym.signature).withSym(sym)
2097
2077
2098
2078
/** Create a term ref with given prefix, name and signature */
2099
- def withSig (prefix : Type , designator : TermName , sig : Signature )(implicit ctx : Context ): TermRef =
2100
- apply(prefix, designator .withSig(sig))
2079
+ def withSig (prefix : Type , name : TermName , sig : Signature )(implicit ctx : Context ): TermRef =
2080
+ apply(prefix, name .withSig(sig))
2101
2081
2102
2082
/** Create a term ref with given prefix, name, signature, and initial denotation */
2103
2083
def withSigAndDenot (prefix : Type , name : TermName , sig : Signature , denot : Denotation )(implicit ctx : Context ): TermRef = {
2104
- if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically || symbolicRefs )
2084
+ if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically)
2105
2085
apply(prefix, denot.symbol.asTerm)
2106
2086
else
2107
2087
withSig(prefix, name, sig)
2108
2088
} withDenot denot
2109
2089
}
2110
2090
2111
2091
object TypeRef {
2092
+
2112
2093
/** Create type ref with given prefix and name */
2113
2094
def apply (prefix : Type , desig : TypeDesignator )(implicit ctx : Context ): TypeRef =
2114
2095
ctx.uniqueNamedTypes.enterIfNew(prefix, desig, isTerm = false ).asInstanceOf [TypeRef ]
2115
2096
2116
- /** Create type ref to given symbol */
2117
- def withSym (prefix : Type , sym : TypeSymbol )(implicit ctx : Context ): TypeRef =
2118
- withSymAndName(prefix, sym, sym.name)
2119
-
2120
- /** Create a type ref referring to given symbol with given name.
2121
- * This is very similar to TypeRef(Type, Symbol),
2122
- * except for two differences:
2123
- * (1) The symbol might not yet have a denotation, so the name needs to be given explicitly.
2124
- * (2) The name in the type ref need not be the same as the name of the Symbol.
2097
+ /** Create a type ref referring to either a given symbol or its name.
2098
+ * This is similar to TypeRef(prefix, sym), except:
2099
+ * (1) the symbol might not yet have a denotation, so the name needs to be given explicitly.
2100
+ * (2) the designator of the TypeRef is either the symbol or its name
2125
2101
*/
2126
- def withSymAndName (prefix : Type , sym : TypeSymbol , name : TypeName )(implicit ctx : Context ): TypeRef =
2102
+ def apply (prefix : Type , sym : TypeSymbol , name : TypeName )(implicit ctx : Context ): TypeRef =
2127
2103
if ((prefix eq NoPrefix ) || sym.isReferencedSymbolically) apply(prefix, sym)
2128
2104
else apply(prefix, name).withSym(sym)
2129
2105
2130
2106
/** Create a type ref with given name and initial denotation */
2131
2107
def apply (prefix : Type , name : TypeName , denot : Denotation )(implicit ctx : Context ): TypeRef = {
2132
- if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically) withSym (prefix, denot.symbol.asType)
2108
+ if ((prefix eq NoPrefix ) || denot.symbol.isReferencedSymbolically) apply (prefix, denot.symbol.asType)
2133
2109
else apply(prefix, name)
2134
2110
} withDenot denot
2135
2111
}
@@ -3416,7 +3392,7 @@ object Types {
3416
3392
appliedRefCache
3417
3393
}
3418
3394
3419
- def symbolicTypeRef (implicit ctx : Context ): TypeRef = TypeRef .withSym (prefix, cls)
3395
+ def symbolicTypeRef (implicit ctx : Context ): TypeRef = TypeRef (prefix, cls, cls.name )
3420
3396
3421
3397
// cached because baseType needs parents
3422
3398
private [this ] var parentsCache : List [Type ] = null
0 commit comments