Skip to content
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

Try to avoid static symbols if leaving them would make a leak #15548

Merged
merged 1 commit into from
Jul 20, 2022
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ object TypeOps:
@threadUnsafe lazy val forbidden = symsToAvoid.toSet
def toAvoid(tp: NamedType) =
val sym = tp.symbol
!sym.isStatic && forbidden.contains(sym)
Copy link
Member

Choose a reason for hiding this comment

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

But shouldn't the anonymous subclass be considered non-static since it's declared in a block? I assume the issue is that its owner is set to the top-level scope, but if we can't change its owner we could perhaps special case ANON_CLASS in SymDenotation#isStatic

forbidden.contains(sym)

override def apply(tp: Type): Type = tp match
case tp: TypeVar if mapCtx.typerState.constraint.contains(tp) =>
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i9314.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
final class fooAnnot[T](member: T) extends scala.annotation.StaticAnnotation // must have type parameter

@fooAnnot(new RecAnnotated {}) // must pass instance of anonymous subclass
trait RecAnnotated