Skip to content

Commit f821a82

Browse files
authored
Merge pull request #3739 from dotty-staging/fix-#3736
Fix #3736: Fix owner checking logic
2 parents 738cefb + acc16ca commit f821a82

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
277277
*
278278
* import owner.feature
279279
*
280-
* (the feature may be bunched with others, or renamed, but wildcard imports
281-
* don't count).
280+
* and there is no visible nested import that excludes the feature, as in
281+
*
282+
* import owner.{ feature => _ }
283+
*
284+
* The feature may be bunched with others, or renamed, but wildcard imports don't count.
282285
*
283286
* 2. The feature is enabled by a compiler option
284287
*
@@ -293,13 +296,16 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
293296
else toPrefix(sym.owner) + sym.name + "."
294297
def featureName = toPrefix(owner) + feature
295298
def hasImport(implicit ctx: Context): Boolean = {
296-
if (ctx.importInfo == null || (ctx.importInfo.site.widen.typeSymbol ne owner)) false
297-
else if (ctx.importInfo.excluded.contains(feature)) false
298-
else if (ctx.importInfo.originals.contains(feature)) true
299+
if (ctx.importInfo eq null) false
299300
else {
300-
var c = ctx.outer
301-
while (c.importInfo eq ctx.importInfo) c = c.outer
302-
hasImport(c)
301+
val isImportOwner = ctx.importInfo.site.widen.typeSymbol eq owner
302+
if (isImportOwner && ctx.importInfo.originals.contains(feature)) true
303+
else if (isImportOwner && ctx.importInfo.excluded.contains(feature)) false
304+
else {
305+
var c = ctx.outer
306+
while (c.importInfo eq ctx.importInfo) c = c.outer
307+
hasImport(c)
308+
}
303309
}
304310
}
305311
def hasOption = ctx.base.settings.language.value exists (s => s == featureName || s == "_")

tests/neg/dynamicNoImport.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ package A {
99
class Foo extends scala.Dynamic // error
1010
trait Bar extends scala.Dynamic // error
1111
object Baz extends scala.Dynamic // error
12+
13+
package C {
14+
import scala.language.{ dynamics => d }
15+
class Foo extends scala.Dynamic // OK
16+
}
1217
}
1318
}

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+
}

tests/pos/i3736.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import scala.language.dynamics
2+
import scala.Nil
3+
class Foo() extends Dynamic

0 commit comments

Comments
 (0)