Skip to content

Commit a4eb251

Browse files
committed
Fix #3736: Fix owner checking logic
1 parent ad96b03 commit a4eb251

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,20 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
292292
if (!sym.exists || (sym eq defn.LanguageModuleClass)) ""
293293
else toPrefix(sym.owner) + sym.name + "."
294294
def featureName = toPrefix(owner) + feature
295-
def hasImport(implicit ctx: Context): Boolean =
296-
ctx.importInfo != null && {
297-
ctx.importInfo.site.widen.typeSymbol == owner &&
298-
!ctx.importInfo.excluded.contains(feature) &&
299-
ctx.importInfo.originals.contains(feature) || {
300-
var c = ctx.outer
301-
while (c.importInfo eq ctx.importInfo) c = c.outer
302-
hasImport(c)
295+
def hasImport(implicit ctx: Context): Boolean = {
296+
if (ctx.importInfo eq null) false
297+
else {
298+
val isImportOwner = ctx.importInfo.site.widen.typeSymbol eq owner
299+
if (isImportOwner && ctx.importInfo.excluded.contains(feature)) false
300+
else if (isImportOwner && ctx.importInfo.originals.contains(feature)) true
301+
else {
302+
def nextImportInfoContext(c: Context): Context =
303+
if (c.importInfo ne ctx.importInfo) c
304+
else nextImportInfoContext(c.outer)
305+
hasImport(nextImportInfoContext(ctx.outer))
303306
}
304307
}
308+
}
305309
def hasOption = ctx.base.settings.language.value exists (s => s == featureName || s == "_")
306310
hasImport(ctx.withPhase(ctx.typerPhase)) || hasOption
307311
}

tests/neg/i3736b.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import foo.dynamics
2+
3+
class Foo() extends Dynamic // error: extension of type scala.Dynamic needs to be enabled
4+
5+
package foo {
6+
class dynamic
7+
}

0 commit comments

Comments
 (0)