Skip to content

Fix #5636: properly type param accessors in constructors #6746

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
Jun 26, 2019
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: 2 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,9 @@ class Typer extends Namer
if (isSelfDenot(defDenot)) curOwner.enclosingClass.thisType
else {
val effectiveOwner =
if (curOwner.isTerm && defDenot.symbol.isType)
if (curOwner.isTerm && defDenot.symbol.maybeOwner.isType)
Copy link
Member Author

Choose a reason for hiding this comment

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

The following alternative check passes all tests too:

Suggested change
if (curOwner.isTerm && defDenot.symbol.maybeOwner.isType)
if (curOwner.isConstructor)

This looks more obviously correct to me, wdyt @odersky ?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I think curOwner could also be localDummy. maybeOwner.isType looks correct.

// Don't mix NoPrefix and thisType prefixes, since type comparer
// would not detect types to be compatible. Note: If we replace the
// 2nd condition by `defDenot.symbol.maybeOwner.isType` we get lots
// of failures in the `tastyBootstrap` test. Trying to compile these
// files in isolation works though.
// TODO: Investigate why that happens.
// would not detect types to be compatible.
defDenot.symbol.owner
else
curOwner
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i5636.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class A
trait Bar[X] {
// same for `val foo: X = ???`
def foo: X = ???
}
// same for `class Foo(...)...`
trait Foo(val a: A) extends Bar[a.type] {
val same: a.type = foo
}