Skip to content

Commit e79c3c9

Browse files
committed
Fix scala#6280: Add missing constructors
1 parent b25d17c commit e79c3c9

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,7 @@ object Types {
24822482
final class CachedSuperType(thistpe: Type, supertpe: Type) extends SuperType(thistpe, supertpe)
24832483

24842484
object SuperType {
2485-
def apply(thistpe: Type, supertpe: Type)(implicit ctx: Context): Type = {
2485+
def apply(thistpe: Type, supertpe: Type)(implicit ctx: Context): SuperType = {
24862486
assert(thistpe != NoPrefix)
24872487
unique(new CachedSuperType(thistpe, supertpe))
24882488
}

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionInternal.scala

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11321132
case _ => None
11331133
}
11341134

1135+
def ConstantType_apply(const: Constant) given (ctx: Context): ConstantType =
1136+
Types.ConstantType(const)
1137+
11351138
def ConstantType_constant(self: ConstantType) given Context: Constant = self.value
11361139

11371140
type SymRef = Types.NamedType
@@ -1145,6 +1148,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11451148
case _ => None
11461149
}
11471150

1151+
def SymRef_apply(qual: Type, sym: Symbol) given (ctx: Context): SymRef =
1152+
Types.NamedType(qual, sym)
1153+
11481154
def SymRef_qualifier(self: SymRef) given Context: TypeOrBounds = self.prefix
11491155

11501156
// TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef
@@ -1168,12 +1174,12 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11681174
case _ => None
11691175
}
11701176

1171-
def TermRef_name(self: TermRef) given Context: String = self.name.toString
1172-
def TermRef_qualifier(self: TermRef) given Context: TypeOrBounds = self.prefix
1173-
11741177
def TermRef_apply(qual: TypeOrBounds, name: String) given Context: TermRef =
11751178
Types.TermRef(qual, name.toTermName)
11761179

1180+
def TermRef_name(self: TermRef) given Context: String = self.name.toString
1181+
def TermRef_qualifier(self: TermRef) given Context: TypeOrBounds = self.prefix
1182+
11771183
type TypeRef = Types.NamedType
11781184

11791185
def matchTypeRef(tpe: TypeOrBounds) given Context: Option[TypeRef] = tpe match {
@@ -1185,6 +1191,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11851191
case _ => None
11861192
}
11871193

1194+
def TypeRef_apply(qual: Type, name: String) given (ctx: Context): TypeRef =
1195+
Types.NamedType(qual, name.toTypeName)
1196+
11881197
def TypeRef_name(self: TypeRef) given Context: String = self.name.toString
11891198
def TypeRef_qualifier(self: TypeRef) given Context: TypeOrBounds = self.prefix
11901199

@@ -1195,6 +1204,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11951204
case _ => None
11961205
}
11971206

1207+
def SuperType_apply(thistpe: Type, supertpe: Type) given Context: SuperType =
1208+
Types.SuperType(thistpe, supertpe)
1209+
11981210
def SuperType_thistpe(self: SuperType) given Context: Type = self.thistpe
11991211
def SuperType_supertpe(self: SuperType) given Context: Type = self.supertpe
12001212

@@ -1205,6 +1217,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12051217
case _ => None
12061218
}
12071219

1220+
def Refinement_apply(parent: Type, name: String, info: Type) given Context: Refinement =
1221+
Types.RefinedType(parent, name.toTypeName, info)
1222+
12081223
def Refinement_parent(self: Refinement) given Context: Type = self.parent
12091224
def Refinement_name(self: Refinement) given Context: String = self.refinedName.toString
12101225
def Refinement_info(self: Refinement) given Context: TypeOrBounds = self.refinedInfo
@@ -1216,6 +1231,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12161231
case _ => None
12171232
}
12181233

1234+
def AppliedType_apply(tycon: Type, args: List[Type]) given Context: AppliedType =
1235+
Types.AppliedType(tycon, args)
1236+
12191237
def AppliedType_tycon(self: AppliedType) given Context: Type = self.tycon
12201238
def AppliedType_args(self: AppliedType) given Context: List[TypeOrBounds] = self.args
12211239

@@ -1226,6 +1244,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12261244
case _ => None
12271245
}
12281246

1247+
def AnnotatedType_apply(parent: Type, annot: Term) given Context: AnnotatedType =
1248+
Types.AnnotatedType(parent, Annotations.Annotation(annot))
1249+
12291250
def AnnotatedType_underlying(self: AnnotatedType) given Context: Type = self.underlying.stripTypeVar
12301251
def AnnotatedType_annot(self: AnnotatedType) given Context: Term = self.annot.tree
12311252

@@ -1236,6 +1257,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12361257
case _ => None
12371258
}
12381259

1260+
def AndType_apply(left: Type, right: Type) given Context: AndType =
1261+
Types.AndType(left, right)
1262+
12391263
def AndType_left(self: AndType) given Context: Type = self.tp1.stripTypeVar
12401264
def AndType_right(self: AndType) given Context: Type = self.tp2.stripTypeVar
12411265

@@ -1246,6 +1270,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12461270
case _ => None
12471271
}
12481272

1273+
def OrType_apply(left: Type, right: Type) given Context: OrType =
1274+
Types.OrType(left, right)
1275+
12491276
def OrType_left(self: OrType) given Context: Type = self.tp1.stripTypeVar
12501277
def OrType_right(self: OrType) given Context: Type = self.tp2.stripTypeVar
12511278

@@ -1267,6 +1294,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12671294
case _ => None
12681295
}
12691296

1297+
def ByNameType_apply(underlying: Type) given Context: ByNameType =
1298+
Types.ExprType(underlying)
1299+
12701300
def ByNameType_underlying(self: ByNameType) given Context: Type = self.resType.stripTypeVar
12711301

12721302
type ParamRef = Types.ParamRef

library/src/scala/tasty/reflect/Internal.scala

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,13 +907,17 @@ trait CompilerInterface {
907907

908908
def matchConstantType(tpe: TypeOrBounds) given (ctx: Context): Option[ConstantType]
909909

910+
def ConstantType_apply(const: Constant) given (ctx: Context): ConstantType
911+
910912
def ConstantType_constant(self: ConstantType) given (ctx: Context): Constant
911913

912914
/** Type of a reference to a symbol */
913915
type SymRef <: Type
914916

915917
def matchSymRef(tpe: TypeOrBounds) given (ctx: Context): Option[SymRef]
916918

919+
def SymRef_apply(qual: Type, sym: Symbol) given (ctx: Context): SymRef
920+
917921
// TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef
918922
def matchSymRef_unapply(tpe: TypeOrBounds) given (ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)]
919923

@@ -924,16 +928,19 @@ trait CompilerInterface {
924928

925929
def matchTermRef(tpe: TypeOrBounds) given (ctx: Context): Option[TermRef]
926930

931+
def TermRef_apply(qual: TypeOrBounds, name: String) given Context: TermRef
932+
927933
def TermRef_name(self: TermRef) given (ctx: Context): String
928934
def TermRef_qualifier(self: TermRef) given (ctx: Context): TypeOrBounds
929935

930-
def TermRef_apply(qual: TypeOrBounds, name: String) given (ctx: Context): TermRef
931936

932937
/** Type of a reference to a type */
933938
type TypeRef <: Type
934939

935940
def matchTypeRef(tpe: TypeOrBounds) given (ctx: Context): Option[TypeRef]
936941

942+
def TypeRef_apply(qual: Type, name: String) given (ctx: Context): TypeRef
943+
937944
def TypeRef_name(self: TypeRef) given (ctx: Context): String
938945
def TypeRef_qualifier(self: TypeRef) given (ctx: Context): TypeOrBounds
939946

@@ -942,6 +949,8 @@ trait CompilerInterface {
942949

943950
def matchSuperType(tpe: TypeOrBounds) given (ctx: Context): Option[SuperType]
944951

952+
def SuperType_apply(thistpe: Type, supertpe: Type) given Context: SuperType
953+
945954
def SuperType_thistpe(self: SuperType) given (ctx: Context): Type
946955
def SuperType_supertpe(self: SuperType) given (ctx: Context): Type
947956

@@ -950,6 +959,8 @@ trait CompilerInterface {
950959

951960
def matchRefinement(tpe: TypeOrBounds) given (ctx: Context): Option[Refinement]
952961

962+
def Refinement_apply(parent: Type, name: String, info: Type) given Context: Refinement
963+
953964
def Refinement_parent(self: Refinement) given (ctx: Context): Type
954965
def Refinement_name(self: Refinement) given (ctx: Context): String
955966
def Refinement_info(self: Refinement) given (ctx: Context): TypeOrBounds
@@ -959,6 +970,8 @@ trait CompilerInterface {
959970

960971
def matchAppliedType(tpe: TypeOrBounds) given (ctx: Context): Option[AppliedType]
961972

973+
def AppliedType_apply(tycon: Type, args: List[Type]) given Context: AppliedType
974+
962975
def AppliedType_tycon(self: AppliedType) given (ctx: Context): Type
963976
def AppliedType_args(self: AppliedType) given (ctx: Context): List[TypeOrBounds]
964977

@@ -967,6 +980,8 @@ trait CompilerInterface {
967980

968981
def matchAnnotatedType(tpe: TypeOrBounds) given (ctx: Context): Option[AnnotatedType]
969982

983+
def AnnotatedType_apply(parent: Type, annot: Term) given Context: AnnotatedType
984+
970985
def AnnotatedType_underlying(self: AnnotatedType) given (ctx: Context): Type
971986
def AnnotatedType_annot(self: AnnotatedType) given (ctx: Context): Term
972987

@@ -975,6 +990,8 @@ trait CompilerInterface {
975990

976991
def matchAndType(tpe: TypeOrBounds) given (ctx: Context): Option[AndType]
977992

993+
def AndType_apply(left: Type, right: Type) given Context: AndType
994+
978995
def AndType_left(self: AndType) given (ctx: Context): Type
979996
def AndType_right(self: AndType) given (ctx: Context): Type
980997

@@ -983,6 +1000,8 @@ trait CompilerInterface {
9831000

9841001
def matchOrType(tpe: TypeOrBounds) given (ctx: Context): Option[OrType]
9851002

1003+
def OrType_apply(left: Type, right: Type) given Context: OrType
1004+
9861005
def OrType_left(self: OrType) given (ctx: Context): Type
9871006
def OrType_right(self: OrType) given (ctx: Context): Type
9881007

@@ -1000,6 +1019,8 @@ trait CompilerInterface {
10001019

10011020
def matchByNameType(tpe: TypeOrBounds) given (ctx: Context): Option[ByNameType]
10021021

1022+
def ByNameType_apply(underlying: Type) given Context: ByNameType
1023+
10031024
def ByNameType_underlying(self: ByNameType) given (ctx: Context): Type
10041025

10051026
/** Type of a parameter reference */

library/src/scala/tasty/reflect/TypeOrBoundsOps.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ trait TypeOrBoundsOps extends Core {
7373
}
7474

7575
object ConstantType {
76+
def apply(const: Constant) given (ctx: Context): ConstantType =
77+
internal.ConstantType_apply(const)
7678
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[Constant] =
7779
internal.matchConstantType(typeOrBounds).map(_.constant)
7880
}
@@ -84,6 +86,8 @@ trait TypeOrBoundsOps extends Core {
8486
}
8587

8688
object SymRef {
89+
def apply(qual: Type, sym: Symbol) given (ctx: Context): SymRef =
90+
internal.SymRef_apply(qual, sym)
8791
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)] =
8892
internal.matchSymRef_unapply(typeOrBounds)
8993
}
@@ -109,6 +113,8 @@ trait TypeOrBoundsOps extends Core {
109113
}
110114

111115
object TypeRef {
116+
def apply(qual: Type, name: String) given (ctx: Context): TypeRef =
117+
internal.TypeRef_apply(qual, name)
112118
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(String, TypeOrBounds /* Type | NoPrefix */)] =
113119
internal.matchTypeRef(typeOrBounds).map(x => (x.name, x.qualifier))
114120
}
@@ -120,6 +126,8 @@ trait TypeOrBoundsOps extends Core {
120126
}
121127

122128
object SuperType {
129+
def apply(thistpe: Type, supertpe: Type) given (ctx: Context): SuperType =
130+
internal.SuperType_apply(thistpe, supertpe)
123131
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(Type, Type)] =
124132
internal.matchSuperType(typeOrBounds).map(x => (x.thistpe, x.supertpe))
125133
}
@@ -131,6 +139,8 @@ trait TypeOrBoundsOps extends Core {
131139
}
132140

133141
object Refinement {
142+
def apply(parent: Type, name: String, info: Type) given (ctx: Context): Refinement =
143+
internal.Refinement_apply(parent, name, info)
134144
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(Type, String, TypeOrBounds /* Type | TypeBounds */)] =
135145
internal.matchRefinement(typeOrBounds).map(x => (x.parent, x.name, x.info))
136146
}
@@ -142,6 +152,8 @@ trait TypeOrBoundsOps extends Core {
142152
}
143153

144154
object AppliedType {
155+
def apply(tycon: Type, args: List[Type]) given (ctx: Context): AppliedType =
156+
internal.AppliedType_apply(tycon, args)
145157
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(Type, List[TypeOrBounds /* Type | TypeBounds */])] =
146158
internal.matchAppliedType(typeOrBounds).map(x => (x.tycon, x.args))
147159
}
@@ -153,6 +165,8 @@ trait TypeOrBoundsOps extends Core {
153165
}
154166

155167
object AnnotatedType {
168+
def apply(parent: Type, annot: Term) given (ctx: Context): AnnotatedType =
169+
internal.AnnotatedType_apply(parent, annot)
156170
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(Type, Term)] =
157171
internal.matchAnnotatedType(typeOrBounds).map(x => (x.underlying, x.annot))
158172
}
@@ -164,6 +178,8 @@ trait TypeOrBoundsOps extends Core {
164178
}
165179

166180
object AndType {
181+
def apply(left: Type, right: Type) given (ctx: Context): AndType =
182+
internal.AndType_apply(left, right)
167183
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(Type, Type)] =
168184
internal.matchAndType(typeOrBounds).map(x => (x.left, x.right))
169185
}
@@ -175,6 +191,8 @@ trait TypeOrBoundsOps extends Core {
175191
}
176192

177193
object OrType {
194+
def apply(left: Type, right: Type) given (ctx: Context): OrType =
195+
internal.OrType_apply(left, right)
178196
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[(Type, Type)] =
179197
internal.matchOrType(typeOrBounds).map(x => (x.left, x.right))
180198
}
@@ -197,6 +215,8 @@ trait TypeOrBoundsOps extends Core {
197215
}
198216

199217
object ByNameType {
218+
def apply(underlying: Type) given Context: ByNameType =
219+
internal.ByNameType_apply(underlying)
200220
def unapply(typeOrBounds: TypeOrBounds) given (ctx: Context): Option[Type] =
201221
internal.matchByNameType(typeOrBounds).map(_.underlying)
202222
}

0 commit comments

Comments
 (0)