Skip to content

Commit

Permalink
Add nowarns for scala/bug#12398
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-kai committed May 29, 2021
1 parent a7a65ac commit caac7b3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object AnyConstructorMacro {
assert(enclosingClass.exists(_.pos == positionOfMakeCall), "enclosingClass must contain macro call position")

def findExprContainingMake(tree: Tree): Option[Tree] = {
@nowarn("msg=outer reference")
val afterLastBlock = Option {
tree
.filter(_.exists(_.pos == positionOfMakeCall))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import izumi.distage.model.reflection.universe.StaticDIUniverse
import izumi.distage.reflection.ReflectionProviderDefaultImpl
import izumi.fundamentals.reflection.{ReflectionUtil, TrivialMacroLogger}

import scala.annotation.nowarn
import scala.reflect.macros.blackbox

object ClassConstructorMacro {
Expand All @@ -16,7 +17,7 @@ object ClassConstructorMacro {
val targetType = ReflectionUtil.norm(c.universe: c.universe.type)(weakTypeOf[T].dealias)
requireConcreteTypeConstructor(c)("ClassConstructor", targetType)

targetType match {
(targetType match {
case t: SingletonTypeApi =>
val functoid = symbolOf[Functoid.type].asClass.module
val term = t match {
Expand Down Expand Up @@ -49,7 +50,7 @@ object ClassConstructorMacro {
val res = c.Expr[ClassConstructor[T]](q"{ new ${weakTypeOf[ClassConstructor[T]]}($provider) }")
logger.log(s"Final syntax tree of class for $targetType:\n$res")
res
}
}): @nowarn("msg=outer reference")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import izumi.distage.model.reflection.universe.StaticDIUniverse
import izumi.distage.model.reflection.{Provider, ReflectionProvider}
import izumi.fundamentals.reflection.ReflectionUtil

import scala.annotation.tailrec
import scala.annotation.{nowarn, tailrec}
import scala.reflect.macros.blackbox

abstract class ClassConstructorMacros extends ConstructorMacrosBase {
Expand Down Expand Up @@ -115,6 +115,7 @@ abstract class FactoryConstructorMacros extends ConstructorMacrosBase {
val u.Wiring.Factory.FactoryMethod(factoryMethod, productConstructor, _) = factoryMethod0

val (methodArgListDecls, methodArgList) = {
@nowarn("msg=outer reference")
@tailrec def instantiatedMethod(tpe: Type): MethodTypeApi = {
tpe match {
case m: MethodTypeApi => m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import izumi.distage.model.reflection.universe.StaticDIUniverse.Aux
import izumi.distage.reflection.ReflectionProviderDefaultImpl
import izumi.fundamentals.reflection.TrivialMacroLogger

import scala.annotation.nowarn
import scala.reflect.macros.blackbox

/**
Expand Down Expand Up @@ -189,12 +190,12 @@ class FunctoidMacro(val c: blackbox.Context) {
}

protected[this] def widenFunctionObject(sig: Type): Type = {
sig match {
(sig match {
case s: SingleTypeApi =>
sig.baseType(s.sym.typeSignature.baseClasses.find(definitions.FunctionClass.seq.contains(_)).get)
case _ =>
sig
}
}): @nowarn("msg=outer reference")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import izumi.distage.model.reflection.ReflectionProvider
import izumi.distage.model.reflection.universe.DIUniverse
import izumi.fundamentals.reflection.{JSRAnnotationTools, ReflectionUtil}

import scala.annotation.nowarn

@nowarn("msg=outer reference")
trait ReflectionProviderDefaultImpl extends ReflectionProvider {

import u.u.{Annotation, LiteralApi}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package izumi.fundamentals.reflection

import scala.annotation.nowarn
import scala.reflect.api.Universe

object JSRAnnotationTools {
Expand All @@ -15,31 +16,24 @@ object JSRAnnotationTools {
* The package name is being ignored
*/
def uniqueJSRNameAnno(u: Universe)(annos: List[u.Annotation]): Option[String] = {
val maybeJSR = annos
.collect {
case a: u.AnnotationApi =>
a.tree.children match {
case (select: u.SelectApi) :: (value: u.NamedArgApi) :: Nil =>
(select.children.headOption, value.lhs, value.rhs) match {
case (Some(n: u.NewApi), i: u.IdentApi, v: u.LiteralApi) if v.value.value.isInstanceOf[String] && i.name.toString == "value" =>
n.children match {
case (head: u.TypeTreeApi) :: Nil if head.symbol.name.toString == "Named" =>
Some(v.value.value.asInstanceOf[String])
case _ =>
None
}
@nowarn("msg=outer reference") @nowarn("msg=abstract type pattern")
val maybeJSR = annos.collect {
case a: u.AnnotationApi =>
a.tree.children match {
case (select: u.SelectApi) :: (value: u.NamedArgApi) :: Nil =>
(select.children.headOption, value.lhs, value.rhs) match {
case (Some(u.New(head: u.TypeTreeApi)), _: u.IdentApi, u.Literal(u.Constant(annotationArgument: String))) if {
head.symbol.name.toString == "Named"
} =>
Some(annotationArgument)

case _ =>
None
}
case _ => None
}

case _ =>
None
}
}
.collect {
case Some(name) => name
}
case _ =>
None
}
}.flatten

maybeJSR match {
case unique :: Nil =>
Expand Down

0 comments on commit caac7b3

Please sign in to comment.