Skip to content

Refine criterion when we can skip an asSeenFrom #10982

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 1 commit into from
Jan 6, 2021
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
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,16 @@ object Denotations {
info.asSeenFrom(pre, owner),
if (symbol.is(Opaque) || this.prefix != NoPrefix) pre else this.prefix)

if (!owner.membersNeedAsSeenFrom(pre) || symbol.is(NonMember)) this
// Tt could happen that we see the symbol with prefix `this` as a member a different class
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Tt could happen that we see the symbol with prefix `this` as a member a different class
// It could happen that we see the symbol with prefix `this` as a member of a different class

Copy link
Contributor

Choose a reason for hiding this comment

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

We have similar logic in Types.scala:

    private def infoDependsOnPrefix(symd: SymDenotation, prefix: Type)(using Context): Boolean =
      symd.maybeOwner.membersNeedAsSeenFrom(prefix) && !symd.is(NonMember)

I'm wondering if it is worth creating a method to abstract the logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting observation! This looked promising at first, but in the end I found no way to improve over the status quo. The problem is that the code in Types only works for SymDenotations, whereas the more complicated logic in Denotations works also for SingleDenotations and it's difficult to break it out.

// through a self type and that it then has a different info. In this case we have to go
// through the asSeenFrom to switch the type back. Test case is pos/i9352.scala.
def hasOriginalInfo: Boolean = this match
case sd: SymDenotation => true
case _ => info eq symbol.info

if !owner.membersNeedAsSeenFrom(pre) && ((pre ne owner.thisType) || hasOriginalInfo)
|| symbol.is(NonMember)
then this
else derived(symbol.info)
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i9352.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
abstract class Foo[B] extends Bar[B]

trait Bar[A]:
self: Foo[A] =>

def foo : Unit = bar(???)
def bar(f: A) : Unit