Skip to content

Commit b379dd7

Browse files
committed
Fix #6280: Add missing constructors
1 parent 10e3990 commit b379dd7

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
@@ -1143,6 +1143,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11431143
case _ => None
11441144
}
11451145

1146+
def ConstantType_apply(const: Constant) given (ctx: Context): ConstantType =
1147+
Types.ConstantType(const)
1148+
11461149
def ConstantType_constant(self: ConstantType) given Context: Constant = self.value
11471150

11481151
type SymRef = Types.NamedType
@@ -1156,6 +1159,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11561159
case _ => None
11571160
}
11581161

1162+
def SymRef_apply(qual: Type, sym: Symbol) given (ctx: Context): SymRef =
1163+
Types.NamedType(qual, sym)
1164+
11591165
def SymRef_qualifier(self: SymRef) given Context: TypeOrBounds = self.prefix
11601166

11611167
// TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef
@@ -1179,12 +1185,12 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11791185
case _ => None
11801186
}
11811187

1182-
def TermRef_name(self: TermRef) given Context: String = self.name.toString
1183-
def TermRef_qualifier(self: TermRef) given Context: TypeOrBounds = self.prefix
1184-
11851188
def TermRef_apply(qual: TypeOrBounds, name: String) given Context: TermRef =
11861189
Types.TermRef(qual, name.toTermName)
11871190

1191+
def TermRef_name(self: TermRef) given Context: String = self.name.toString
1192+
def TermRef_qualifier(self: TermRef) given Context: TypeOrBounds = self.prefix
1193+
11881194
type TypeRef = Types.NamedType
11891195

11901196
def matchTypeRef(tpe: TypeOrBounds) given Context: Option[TypeRef] = tpe match {
@@ -1196,6 +1202,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
11961202
case _ => None
11971203
}
11981204

1205+
def TypeRef_apply(qual: Type, name: String) given (ctx: Context): TypeRef =
1206+
Types.NamedType(qual, name.toTypeName)
1207+
11991208
def TypeRef_name(self: TypeRef) given Context: String = self.name.toString
12001209
def TypeRef_qualifier(self: TypeRef) given Context: TypeOrBounds = self.prefix
12011210

@@ -1206,6 +1215,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12061215
case _ => None
12071216
}
12081217

1218+
def SuperType_apply(thistpe: Type, supertpe: Type) given Context: SuperType =
1219+
Types.SuperType(thistpe, supertpe)
1220+
12091221
def SuperType_thistpe(self: SuperType) given Context: Type = self.thistpe
12101222
def SuperType_supertpe(self: SuperType) given Context: Type = self.supertpe
12111223

@@ -1216,6 +1228,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12161228
case _ => None
12171229
}
12181230

1231+
def Refinement_apply(parent: Type, name: String, info: Type) given Context: Refinement =
1232+
Types.RefinedType(parent, name.toTypeName, info)
1233+
12191234
def Refinement_parent(self: Refinement) given Context: Type = self.parent
12201235
def Refinement_name(self: Refinement) given Context: String = self.refinedName.toString
12211236
def Refinement_info(self: Refinement) given Context: TypeOrBounds = self.refinedInfo
@@ -1227,6 +1242,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12271242
case _ => None
12281243
}
12291244

1245+
def AppliedType_apply(tycon: Type, args: List[Type]) given Context: AppliedType =
1246+
Types.AppliedType(tycon, args)
1247+
12301248
def AppliedType_tycon(self: AppliedType) given Context: Type = self.tycon
12311249
def AppliedType_args(self: AppliedType) given Context: List[TypeOrBounds] = self.args
12321250

@@ -1237,6 +1255,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12371255
case _ => None
12381256
}
12391257

1258+
def AnnotatedType_apply(parent: Type, annot: Term) given Context: AnnotatedType =
1259+
Types.AnnotatedType(parent, Annotations.Annotation(annot))
1260+
12401261
def AnnotatedType_underlying(self: AnnotatedType) given Context: Type = self.underlying.stripTypeVar
12411262
def AnnotatedType_annot(self: AnnotatedType) given Context: Term = self.annot.tree
12421263

@@ -1247,6 +1268,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12471268
case _ => None
12481269
}
12491270

1271+
def AndType_apply(left: Type, right: Type) given Context: AndType =
1272+
Types.AndType(left, right)
1273+
12501274
def AndType_left(self: AndType) given Context: Type = self.tp1.stripTypeVar
12511275
def AndType_right(self: AndType) given Context: Type = self.tp2.stripTypeVar
12521276

@@ -1257,6 +1281,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12571281
case _ => None
12581282
}
12591283

1284+
def OrType_apply(left: Type, right: Type) given Context: OrType =
1285+
Types.OrType(left, right)
1286+
12601287
def OrType_left(self: OrType) given Context: Type = self.tp1.stripTypeVar
12611288
def OrType_right(self: OrType) given Context: Type = self.tp2.stripTypeVar
12621289

@@ -1278,6 +1305,9 @@ class ReflectionCompilerInterface(val rootContext: core.Contexts.Context) extend
12781305
case _ => None
12791306
}
12801307

1308+
def ByNameType_apply(underlying: Type) given Context: ByNameType =
1309+
Types.ExprType(underlying)
1310+
12811311
def ByNameType_underlying(self: ByNameType) given Context: Type = self.resType.stripTypeVar
12821312

12831313
type ParamRef = Types.ParamRef

library/src/scala/tasty/reflect/CompilerInterface.scala

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

924924
def matchConstantType(tpe: TypeOrBounds) given (ctx: Context): Option[ConstantType]
925925

926+
def ConstantType_apply(const: Constant) given (ctx: Context): ConstantType
927+
926928
def ConstantType_constant(self: ConstantType) given (ctx: Context): Constant
927929

928930
/** Type of a reference to a symbol */
929931
type SymRef <: Type
930932

931933
def matchSymRef(tpe: TypeOrBounds) given (ctx: Context): Option[SymRef]
932934

935+
def SymRef_apply(qual: Type, sym: Symbol) given (ctx: Context): SymRef
936+
933937
// TODO remove this method. May require splitting SymRef into TypeSymRef and TermSymRef
934938
def matchSymRef_unapply(tpe: TypeOrBounds) given (ctx: Context): Option[(Symbol, TypeOrBounds /* Type | NoPrefix */)]
935939

@@ -940,16 +944,19 @@ trait CompilerInterface {
940944

941945
def matchTermRef(tpe: TypeOrBounds) given (ctx: Context): Option[TermRef]
942946

947+
def TermRef_apply(qual: TypeOrBounds, name: String) given Context: TermRef
948+
943949
def TermRef_name(self: TermRef) given (ctx: Context): String
944950
def TermRef_qualifier(self: TermRef) given (ctx: Context): TypeOrBounds
945951

946-
def TermRef_apply(qual: TypeOrBounds, name: String) given (ctx: Context): TermRef
947952

948953
/** Type of a reference to a type */
949954
type TypeRef <: Type
950955

951956
def matchTypeRef(tpe: TypeOrBounds) given (ctx: Context): Option[TypeRef]
952957

958+
def TypeRef_apply(qual: Type, name: String) given (ctx: Context): TypeRef
959+
953960
def TypeRef_name(self: TypeRef) given (ctx: Context): String
954961
def TypeRef_qualifier(self: TypeRef) given (ctx: Context): TypeOrBounds
955962

@@ -958,6 +965,8 @@ trait CompilerInterface {
958965

959966
def matchSuperType(tpe: TypeOrBounds) given (ctx: Context): Option[SuperType]
960967

968+
def SuperType_apply(thistpe: Type, supertpe: Type) given Context: SuperType
969+
961970
def SuperType_thistpe(self: SuperType) given (ctx: Context): Type
962971
def SuperType_supertpe(self: SuperType) given (ctx: Context): Type
963972

@@ -966,6 +975,8 @@ trait CompilerInterface {
966975

967976
def matchRefinement(tpe: TypeOrBounds) given (ctx: Context): Option[Refinement]
968977

978+
def Refinement_apply(parent: Type, name: String, info: Type) given Context: Refinement
979+
969980
def Refinement_parent(self: Refinement) given (ctx: Context): Type
970981
def Refinement_name(self: Refinement) given (ctx: Context): String
971982
def Refinement_info(self: Refinement) given (ctx: Context): TypeOrBounds
@@ -975,6 +986,8 @@ trait CompilerInterface {
975986

976987
def matchAppliedType(tpe: TypeOrBounds) given (ctx: Context): Option[AppliedType]
977988

989+
def AppliedType_apply(tycon: Type, args: List[Type]) given Context: AppliedType
990+
978991
def AppliedType_tycon(self: AppliedType) given (ctx: Context): Type
979992
def AppliedType_args(self: AppliedType) given (ctx: Context): List[TypeOrBounds]
980993

@@ -983,6 +996,8 @@ trait CompilerInterface {
983996

984997
def matchAnnotatedType(tpe: TypeOrBounds) given (ctx: Context): Option[AnnotatedType]
985998

999+
def AnnotatedType_apply(parent: Type, annot: Term) given Context: AnnotatedType
1000+
9861001
def AnnotatedType_underlying(self: AnnotatedType) given (ctx: Context): Type
9871002
def AnnotatedType_annot(self: AnnotatedType) given (ctx: Context): Term
9881003

@@ -991,6 +1006,8 @@ trait CompilerInterface {
9911006

9921007
def matchAndType(tpe: TypeOrBounds) given (ctx: Context): Option[AndType]
9931008

1009+
def AndType_apply(left: Type, right: Type) given Context: AndType
1010+
9941011
def AndType_left(self: AndType) given (ctx: Context): Type
9951012
def AndType_right(self: AndType) given (ctx: Context): Type
9961013

@@ -999,6 +1016,8 @@ trait CompilerInterface {
9991016

10001017
def matchOrType(tpe: TypeOrBounds) given (ctx: Context): Option[OrType]
10011018

1019+
def OrType_apply(left: Type, right: Type) given Context: OrType
1020+
10021021
def OrType_left(self: OrType) given (ctx: Context): Type
10031022
def OrType_right(self: OrType) given (ctx: Context): Type
10041023

@@ -1016,6 +1035,8 @@ trait CompilerInterface {
10161035

10171036
def matchByNameType(tpe: TypeOrBounds) given (ctx: Context): Option[ByNameType]
10181037

1038+
def ByNameType_apply(underlying: Type) given Context: ByNameType
1039+
10191040
def ByNameType_underlying(self: ByNameType) given (ctx: Context): Type
10201041

10211042
/** 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)