@@ -6,6 +6,7 @@ import core._
66import util .Spans ._ , Types ._ , Contexts ._ , Constants ._ , Names ._ , NameOps ._ , Flags ._
77import Symbols ._ , StdNames ._ , Trees ._ , ContextOps ._
88import Decorators ._ , transform .SymUtils ._
9+ import Annotations .Annotation
910import NameKinds .{UniqueName , EvidenceParamName , DefaultGetterName , WildcardParamName }
1011import typer .{Namer , Checking }
1112import util .{Property , SourceFile , SourcePosition , Chars }
@@ -117,7 +118,7 @@ object desugar {
117118 if (local.exists) (defctx.owner.thisType select local).dealiasKeepAnnots
118119 else {
119120 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}"
121122 ErrorType (msg).assertingErrorsReported(msg)
122123 }
123124 case _ =>
@@ -165,32 +166,41 @@ object desugar {
165166 *
166167 * Generate setter where needed
167168 */
168- def valDef (vdef0 : ValDef )(using Context ): Tree = {
169+ def valDef (vdef0 : ValDef )(using Context ): Tree =
169170 val vdef @ ValDef (_, tpt, rhs) = vdef0
170- val mods = vdef.mods
171-
172171 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)
174189
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
180191 val setterParam = makeSyntheticParameter(tpt = SetterParamTree ().watching(vdef))
181192 // The rhs gets filled in later, when field is generated and getter has parameters (see Memoize miniphase)
182193 val setterRhs = if (vdef.rhs.isEmpty) EmptyTree else unitLiteral
183194 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
190201 Thicket (vdef1, setter)
191- }
192202 else vdef1
193- }
203+ end valDef
194204
195205 def makeImplicitParameters (tpts : List [Tree ], implicitFlag : FlagSet , forPrimaryConstructor : Boolean = false )(using Context ): List [ValDef ] =
196206 for (tpt <- tpts) yield {
@@ -911,7 +921,7 @@ object desugar {
911921 case params :: paramss1 => // `params` must have a single parameter and without `given` flag
912922
913923 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)
915925 extParamss ++ mdef.paramss
916926
917927 params match
@@ -1137,7 +1147,7 @@ object desugar {
11371147 def errorOnGivenBinding (bind : Bind )(using Context ): Boolean =
11381148 report.error(
11391149 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)
11411151 false
11421152
11431153 def isTuplePattern (arity : Int ): Boolean = pat match {
@@ -1237,7 +1247,7 @@ object desugar {
12371247 def checkOpaqueAlias (tree : MemberDef )(using Context ): MemberDef =
12381248 def check (rhs : Tree ): MemberDef = rhs match
12391249 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)
12411251 tree.withMods(tree.mods.withoutFlags(Opaque ))
12421252 case LambdaTypeTree (_, body) => check(body)
12431253 case _ => tree
0 commit comments