Skip to content

Fix #8750: Strip opaque refinements when checking self type #8751

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
Apr 20, 2020
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: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,16 @@ object Checking {
if (cls.isOneOf(AbstractOrTrait))
ctx.error(CantInstantiateAbstractClassOrTrait(cls, isTrait = cls.is(Trait)), posd.sourcePos)
if (!cls.is(Module)) {
def (tp: Type).stripOpaques: Type = tp match
case RefinedType(parent, name, _) if cls.info.decl(name).symbol.isOpaqueAlias =>
parent.stripOpaques
case _ =>
tp
// Create a synthetic singleton type instance, and check whether
// it conforms to the self type of the class as seen from that instance.
val stp = SkolemType(tp)
val selfType = cls.asClass.givenSelfType.asSeenFrom(stp, cls)
val selfType =
cls.asClass.givenSelfType.stripOpaques.asSeenFrom(stp, cls)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe stripOpaque should be a boolean parameter of givenSelfTypes ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's safer to keep givenSelfType as is. It's really just when checking that we need to strip the refinements.

if (selfType.exists && !(stp <:< selfType))
ctx.error(DoesNotConformToSelfTypeCantBeInstantiated(tp, selfType), posd.sourcePos)
}
Expand Down
4 changes: 4 additions & 0 deletions tests/pos/i8750.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Abc:
opaque type Log = Double

val v : Abc = new Abc