Skip to content

Commit e5119a0

Browse files
committed
Address @smarter's review comments
1 parent 6821bac commit e5119a0

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
455455
}
456456
}
457457

458-
/** If tree is a closure, it's body, otherwise tree itself */
458+
/** If tree is a closure, its body, otherwise tree itself */
459459
def closureBody(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
460460
case Block((meth @ DefDef(nme.ANON_FUN, _, _, _, _)) :: Nil, Closure(_, _, _)) => meth.rhs
461461
case _ => tree

src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ object Trees {
520520
case class Inlined[-T >: Untyped] private[ast] (call: tpd.Tree, bindings: List[MemberDef[T]], expansion: Tree[T])
521521
extends Tree[T] {
522522
type ThisTree[-T >: Untyped] = Inlined[T]
523-
}
523+
}
524524

525525
/** A type tree that represents an existing or inferred type */
526526
case class TypeTree[-T >: Untyped] private[ast] (original: Tree[T])

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ object Flags {
529529
/** Either method or lazy or deferred */
530530
final val MethodOrLazyOrDeferred = Method | Lazy | Deferred
531531

532-
/** Labeled `private` or `final` */
532+
/** Labeled `private`, `final`, or `inline` */
533533
final val PrivateOrFinalOrInline = Private | Final | Inline
534534

535535
/** A private method */

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ object Types {
24482448
}
24492449
/** Add @inlineParam to inline call-by-value parameters */
24502450
def translateInline(tp: Type): Type = tp match {
2451-
case tp @ ExprType(tp1) => tp
2451+
case _: ExprType => tp
24522452
case _ => AnnotatedType(tp, Annotation(defn.InlineParamAnnot))
24532453
}
24542454
def paramInfo(param: Symbol): Type = {
@@ -2580,7 +2580,7 @@ object Types {
25802580
x => paramBounds mapConserve (_.subst(this, x).bounds),
25812581
x => resType.subst(this, x))
25822582

2583-
/** Merge nested polytypes into one polytype. nested polytypes are normally not suported
2583+
/** Merge nested polytypes into one polytype. nested polytypes are normally not supported
25842584
* but can arise as temporary data structures.
25852585
*/
25862586
def flatten(implicit ctx: Context): PolyType = resType match {

src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ object Scanners {
220220

221221

222222
private def treatAsIdent() = {
223-
testScala2Mode(i"$name is now a keyword, put in `...` to keep as an identifier")
223+
testScala2Mode(i"$name is now a keyword, write `$name` instead of $name to keep it as an identifier")
224224
patch(source, Position(offset), "`")
225225
patch(source, Position(offset + name.length), "`")
226226
IDENTIFIER

src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,22 @@ object Inliner {
8080
*/
8181
def addAccessor(tree: Tree, refPart: Tree, targs: List[Tree], argss: List[List[Tree]],
8282
accessedType: Type, rhs: (Tree, List[Type], List[List[Tree]]) => Tree)(implicit ctx: Context): Tree = {
83+
val qual = qualifier(refPart)
84+
def refIsLocal = qual match {
85+
case qual: This => qual.symbol == refPart.symbol.owner
86+
case _ => false
87+
}
8388
val (accessorDef, accessorRef) =
84-
if (refPart.symbol.isStatic) {
85-
// Easy case: Reference to a static symbol
89+
if (refPart.symbol.isStatic || refIsLocal) {
90+
// Easy case: Reference to a static symbol or a symbol referenced via `this.`
8691
val accessorType = accessedType.ensureMethodic
8792
val accessor = accessorSymbol(tree, accessorType).asTerm
8893
val accessorDef = polyDefDef(accessor, tps => argss =>
8994
rhs(refPart, tps, argss))
9095
val accessorRef = ref(accessor).appliedToTypeTrees(targs).appliedToArgss(argss)
9196
(accessorDef, accessorRef)
9297
} else {
93-
// Hard case: Reference needs to go via a dyanmic prefix
94-
val qual = qualifier(refPart)
98+
// Hard case: Reference needs to go via a dynamic prefix
9599
inlining.println(i"adding inline accessor for $tree -> (${qual.tpe}, $refPart: ${refPart.getClass}, [$targs%, %], ($argss%, %))")
96100

97101
// Need to dealias in order to catch all possible references to abstracted over types in
@@ -246,12 +250,11 @@ object Inliner {
246250
tpd.seq(inlined.bindings, reposition.transform(inlined.expansion))
247251
}
248252

249-
/** The qualifier part of a Select, Ident, or SelectFromTypeTree tree.
253+
/** The qualifier part of a Select or Ident.
250254
* For an Ident, this is the `This` of the current class. (TODO: use elsewhere as well?)
251255
*/
252256
private def qualifier(tree: Tree)(implicit ctx: Context) = tree match {
253257
case Select(qual, _) => qual
254-
case SelectFromTypeTree(qual, _) => qual
255258
case _ => This(ctx.owner.enclosingClass.asClass)
256259
}
257260
}

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
13571357
def typedTypedSplice(tree: untpd.TypedSplice)(implicit ctx: Context): Tree =
13581358
tree.tree match {
13591359
case tree1: TypeTree => tree1 // no change owner necessary here ...
1360-
case tree1: Ident => tree1 // ... or here
1360+
case tree1: Ident => tree1 // ... or here, since these trees cannot contain bindings
13611361
case tree1 =>
13621362
if (ctx.owner ne tree.owner) tree1.changeOwner(tree.owner, ctx.owner)
13631363
else tree1
@@ -1859,7 +1859,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
18591859
if (folded ne tree) return adaptConstant(folded, folded.tpe.asInstanceOf[ConstantType])
18601860
// drop type if prototype is Unit
18611861
if (pt isRef defn.UnitClass)
1862-
return tpd.Block(tree :: Nil, Literal(Constant(())))
1862+
return adapt(tpd.Block(tree :: Nil, Literal(Constant(()))), pt)
18631863
// convert function literal to SAM closure
18641864
tree match {
18651865
case Closure(Nil, id @ Ident(nme.ANON_FUN), _)

tests/run/inlinedAssign.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
object Test {
22

33
inline def swap[T](x: T, inline x_= : T => Unit, y: T, inline y_= : T => Unit) = {
4-
val t = x
54
x_=(y)
6-
y_=(t)
5+
y_=(x)
76
}
87

98
inline def f(x: Int => Unit) = x

0 commit comments

Comments
 (0)