Skip to content

Add missing annotation shapes #4681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/tastyreflect/TastyImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,12 @@ object TastyImpl extends scala.tasty.Tasty {
else None
}

def annots(implicit ctx: Context): List[Term] =
x.symbol.annotations.map(_.tree)
def annots(implicit ctx: Context): List[Term] = {
x.symbol.annotations.flatMap {
case _: core.Annotations.LazyBodyAnnotation => Nil
case annot => annot.tree :: Nil
}
}

def localContext(implicit ctx: Context): Context =
if (x.hasType && x.symbol.exists) ctx.withOwner(x.symbol)
Expand Down
16 changes: 6 additions & 10 deletions library/src/scala/tasty/util/ShowSourceCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty

val flags = ddef.flags
if (flags.isImplicit) this += "implicit "
if (flags.isInline) this += "inline "
if (flags.isOverride) this += "override "

this += "def " += name
Expand All @@ -231,16 +232,8 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
}
this

case tree @ Term.Ident(name) =>
tree.tpe match {
case Type.SymRef(_, Types.EmptyPrefix()) | Type.TermRef(_, Types.EmptyPrefix()) => this += name
case Type.SymRef(_, prefix) =>
printTypeOrBound(prefix)
this += "." += name
case Type.TermRef(_, prefix) =>
printTypeOrBound(prefix)
this += "." += name
}
case tree @ Term.Ident(_) =>
printType(tree.tpe)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification 👍


case Term.Select(qual, name, sig) =>
printTree(qual)
Expand Down Expand Up @@ -907,6 +900,7 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty
case Type.TypeRef(_, Type.SymRef(PackageDef("internal", _), Type.ThisType(Type.SymRef(PackageDef("annotation", _), NoPrefix())))) => false
case _ => true
}
case x => throw new MatchError(x.show)
}
printAnnotations(annots)
if (annots.nonEmpty) this += " "
Expand Down Expand Up @@ -969,7 +963,9 @@ class ShowSourceCode[T <: Tasty with Singleton](tasty0: T) extends Show[T](tasty

private object Annotation {
def unapply(arg: Tree)(implicit ctx: Context): Option[(TypeTree, List[Term])] = arg match {
case Term.New(annot) => Some((annot, Nil))
case Term.Apply(Term.Select(Term.New(annot), "<init>", _), args) => Some((annot, args))
case Term.Apply(Term.TypeApply(Term.Select(Term.New(annot), "<init>", _), targs), args) => Some((annot, args))
case _ => None
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i1570.decompiled
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** Decompiled from out/posTestFromTasty/pos/i1570/Test.class */
object Test {
inline def foo(n: scala.Int): scala.Int = Test.bar(n)
inline def bar(n: scala.Int): scala.Int = n
}