Skip to content

Commit

Permalink
Tweak setInfo and do not warn on return of arg
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed Jul 27, 2022
1 parent 5c10689 commit 68080c2
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/reflect/scala/reflect/api/Internals.scala
Expand Up @@ -530,7 +530,7 @@ trait Internals { self: Universe =>
/** Set symbol's type signature to given type.
* @return the symbol itself
*/
def setInfo[S <: Symbol](sym: S, tpe: Type): S
def setInfo[S <: Symbol](sym: S, tpe: Type): sym.type

/** Set symbol's annotations to given annotations `annots`.
*/
Expand Down
Expand Up @@ -60,7 +60,7 @@ trait ReificationSupport { self: SymbolTable =>
def setAnnotations[S <: Symbol](sym: S, annots: List[AnnotationInfo]): S =
sym.setAnnotations(annots)

def setInfo[S <: Symbol](sym: S, tpe: Type): S =
def setInfo[S <: Symbol](sym: S, tpe: Type): sym.type =
sym.setInfo(tpe).markAllCompleted()

def mkThis(sym: Symbol): Tree = self.This(sym)
Expand Down
8 changes: 5 additions & 3 deletions src/reflect/scala/reflect/internal/TreeInfo.scala
Expand Up @@ -356,10 +356,12 @@ abstract class TreeInfo {
* where the op is an assignment operator.
*/
def isThisTypeResult(tree: Tree): Boolean = tree match {
case Applied(fun @ Select(receiver, op), _, _) =>
case Applied(fun @ Select(receiver, op), _, argss) =>
tree.tpe match {
case ThisType(sym) => sym == receiver.symbol
case SingleType(_, sym) => sym == receiver.symbol
case ThisType(sym) =>
sym == receiver.symbol
case SingleType(p, sym) =>
sym == receiver.symbol || argss.exists(_.exists(sym == _.symbol))
case _ =>
def check(sym: Symbol): Boolean =
(sym == receiver.symbol) || {
Expand Down
8 changes: 8 additions & 0 deletions test/files/neg/nonunit-statement.scala
Expand Up @@ -189,3 +189,11 @@ final class ArrayOops[A](private val xs: Array[A]) extends AnyVal {
}
}
}
class Depends {
def f[A](a: A): a.type = a
def g() = {
val d = new Depends
f(d)
()
}
}
31 changes: 31 additions & 0 deletions test/files/pos/skunky-expansion.scala
@@ -0,0 +1,31 @@
// scalac: -Werror -Wnonunit-statement
//
import scala.reflect.macros._
import scala.reflect.api.TypeCreator

abstract trait Encoder[A] extends scala.AnyRef;
object StringContextOps extends scala.AnyRef {
class StringOpsMacros(c: scala.reflect.macros.whitebox.Context) extends scala.AnyRef {
def sql_impl(argSeq: StringOpsMacros.this.c.universe.Tree*): AnyRef = {
val EncoderType: StringOpsMacros.this.c.universe.Type = StringOpsMacros.this.c.universe.typeOf[Encoder[_]](({
val $u: StringOpsMacros.this.c.universe.type = StringOpsMacros.this.c.universe;
val $m: $u.Mirror = StringOpsMacros.this.c.universe.rootMirror;
$u.TypeTag.apply[Encoder[_]]($m, {
final class $typecreator1 extends TypeCreator {
def apply[U <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
val $u: U = $m$untyped.universe;
val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
val symdef$EncoderType1: $u.Symbol = $u.internal.reificationSupport.newNestedSymbol($u.internal.reificationSupport.selectTerm($u.internal.reificationSupport.selectType($m.staticModule("StringContextOps").asModule.moduleClass, "StringOpsMacros"), "sql_impl"), $u.TermName.apply("EncoderType"), $u.NoPosition, $u.internal.reificationSupport.FlagsRepr.apply(549755813888L), false);
val symdef$_$11: $u.Symbol = $u.internal.reificationSupport.newNestedSymbol(symdef$EncoderType1, $u.TypeName.apply("_$1"), $u.NoPosition, $u.internal.reificationSupport.FlagsRepr.apply(34359738384L), false);
$u.internal.reificationSupport.setInfo[$u.Symbol](symdef$EncoderType1, $u.NoType);
$u.internal.reificationSupport.setInfo[$u.Symbol](symdef$_$11, $u.internal.reificationSupport.TypeBounds($m.staticClass("scala.Nothing").asType.toTypeConstructor, $m.staticClass("scala.Any").asType.toTypeConstructor));
$u.internal.reificationSupport.ExistentialType(scala.collection.immutable.List.apply[$u.Symbol](symdef$_$11), $u.internal.reificationSupport.TypeRef($u.internal.reificationSupport.thisPrefix($m.EmptyPackageClass), $m.staticClass("Encoder"), scala.collection.immutable.List.apply[$u.Type]($u.internal.reificationSupport.TypeRef($u.NoPrefix, symdef$_$11, scala.collection.immutable.Nil))))
}
};
new $typecreator1()
})
}: StringOpsMacros.this.c.universe.TypeTag[Encoder[_]]));
argSeq.head
}
}
}
15 changes: 15 additions & 0 deletions test/files/pos/skunky.scala
@@ -0,0 +1,15 @@
// scalac: -Werror -Wnonunit-statement

import scala.reflect.macros._

trait Encoder[A]

object StringContextOps {
class StringOpsMacros(val c: whitebox.Context) {
import c.universe._
def sql_impl(argSeq: Tree*): Tree = {
val EncoderType = typeOf[Encoder[_]]
argSeq.head
}
}
}

0 comments on commit 68080c2

Please sign in to comment.