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