@@ -6,6 +6,7 @@ import core._
6
6
import util .Spans ._ , Types ._ , Contexts ._ , Constants ._ , Names ._ , NameOps ._ , Flags ._
7
7
import Symbols ._ , StdNames ._ , Trees ._ , ContextOps ._
8
8
import Decorators ._ , transform .SymUtils ._
9
+ import Annotations .Annotation
9
10
import NameKinds .{UniqueName , EvidenceParamName , DefaultGetterName , WildcardParamName }
10
11
import typer .{Namer , Checking }
11
12
import util .{Property , SourceFile , SourcePosition , Chars }
@@ -117,7 +118,7 @@ object desugar {
117
118
if (local.exists) (defctx.owner.thisType select local).dealiasKeepAnnots
118
119
else {
119
120
def msg =
120
- s " no matching symbol for ${tp.symbol.showLocated} in ${defctx.owner} / ${defctx.effectiveScope.toList}"
121
+ em " no matching symbol for ${tp.symbol.showLocated} in ${defctx.owner} / ${defctx.effectiveScope.toList}"
121
122
ErrorType (msg).assertingErrorsReported(msg)
122
123
}
123
124
case _ =>
@@ -165,32 +166,41 @@ object desugar {
165
166
*
166
167
* Generate setter where needed
167
168
*/
168
- def valDef (vdef0 : ValDef )(using Context ): Tree = {
169
+ def valDef (vdef0 : ValDef )(using Context ): Tree =
169
170
val vdef @ ValDef (_, tpt, rhs) = vdef0
170
- val mods = vdef.mods
171
-
172
171
val valName = normalizeName(vdef, tpt).asTermName
173
- val vdef1 = cpy.ValDef (vdef)(name = valName)
172
+ var mods1 = vdef.mods
173
+
174
+ def dropInto (tpt : Tree ): Tree = tpt match
175
+ case Into (tpt1) =>
176
+ mods1 = vdef.mods.withAddedAnnotation(
177
+ TypedSplice (
178
+ Annotation (defn.AllowConversionsAnnot ).tree.withSpan(tpt.span.startPos)))
179
+ tpt1
180
+ case ByNameTypeTree (tpt1) =>
181
+ cpy.ByNameTypeTree (tpt)(dropInto(tpt1))
182
+ case PostfixOp (tpt1, op) if op.name == tpnme.raw.STAR =>
183
+ cpy.PostfixOp (tpt)(dropInto(tpt1), op)
184
+ case _ =>
185
+ tpt
186
+
187
+ val vdef1 = cpy.ValDef (vdef)(name = valName, tpt = dropInto(tpt))
188
+ .withMods(mods1)
174
189
175
- if (isSetterNeeded(vdef)) {
176
- // TODO: copy of vdef as getter needed?
177
- // val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos?
178
- // right now vdef maps via expandedTree to a thicket which concerns itself.
179
- // I don't see a problem with that but if there is one we can avoid it by making a copy here.
190
+ if isSetterNeeded(vdef) then
180
191
val setterParam = makeSyntheticParameter(tpt = SetterParamTree ().watching(vdef))
181
192
// The rhs gets filled in later, when field is generated and getter has parameters (see Memoize miniphase)
182
193
val setterRhs = if (vdef.rhs.isEmpty) EmptyTree else unitLiteral
183
194
val setter = cpy.DefDef (vdef)(
184
- name = valName.setterName,
185
- paramss = (setterParam :: Nil ) :: Nil ,
186
- tpt = TypeTree (defn.UnitType ),
187
- rhs = setterRhs
188
- ).withMods((mods | Accessor ) &~ (CaseAccessor | GivenOrImplicit | Lazy ))
189
- .dropEndMarker() // the end marker should only appear on the getter definition
195
+ name = valName.setterName,
196
+ paramss = (setterParam :: Nil ) :: Nil ,
197
+ tpt = TypeTree (defn.UnitType ),
198
+ rhs = setterRhs
199
+ ).withMods((vdef. mods | Accessor ) &~ (CaseAccessor | GivenOrImplicit | Lazy ))
200
+ .dropEndMarker() // the end marker should only appear on the getter definition
190
201
Thicket (vdef1, setter)
191
- }
192
202
else vdef1
193
- }
203
+ end valDef
194
204
195
205
def makeImplicitParameters (tpts : List [Tree ], implicitFlag : FlagSet , forPrimaryConstructor : Boolean = false )(using Context ): List [ValDef ] =
196
206
for (tpt <- tpts) yield {
@@ -911,7 +921,7 @@ object desugar {
911
921
case params :: paramss1 => // `params` must have a single parameter and without `given` flag
912
922
913
923
def badRightAssoc (problem : String ) =
914
- report.error(i " right-associative extension method $problem" , mdef.srcPos)
924
+ report.error(em " right-associative extension method $problem" , mdef.srcPos)
915
925
extParamss ++ mdef.paramss
916
926
917
927
params match
@@ -1137,7 +1147,7 @@ object desugar {
1137
1147
def errorOnGivenBinding (bind : Bind )(using Context ): Boolean =
1138
1148
report.error(
1139
1149
em """ ${hl(" given" )} patterns are not allowed in a ${hl(" val" )} definition,
1140
- |please bind to an identifier and use an alias given. """ .stripMargin , bind)
1150
+ |please bind to an identifier and use an alias given. """ , bind)
1141
1151
false
1142
1152
1143
1153
def isTuplePattern (arity : Int ): Boolean = pat match {
@@ -1237,7 +1247,7 @@ object desugar {
1237
1247
def checkOpaqueAlias (tree : MemberDef )(using Context ): MemberDef =
1238
1248
def check (rhs : Tree ): MemberDef = rhs match
1239
1249
case bounds : TypeBoundsTree if bounds.alias.isEmpty =>
1240
- report.error(i " opaque type must have a right-hand side " , tree.srcPos)
1250
+ report.error(em " opaque type must have a right-hand side " , tree.srcPos)
1241
1251
tree.withMods(tree.mods.withoutFlags(Opaque ))
1242
1252
case LambdaTypeTree (_, body) => check(body)
1243
1253
case _ => tree
0 commit comments