diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index c940a0ec45fb..b0df2d7feec0 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -277,8 +277,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object. * * import owner.feature * - * (the feature may be bunched with others, or renamed, but wildcard imports - * don't count). + * and there is no visible nested import that excludes the feature, as in + * + * import owner.{ feature => _ } + * + * The feature may be bunched with others, or renamed, but wildcard imports don't count. * * 2. The feature is enabled by a compiler option * @@ -293,13 +296,16 @@ trait TypeOps { this: Context => // TODO: Make standalone object. else toPrefix(sym.owner) + sym.name + "." def featureName = toPrefix(owner) + feature def hasImport(implicit ctx: Context): Boolean = { - if (ctx.importInfo == null || (ctx.importInfo.site.widen.typeSymbol ne owner)) false - else if (ctx.importInfo.excluded.contains(feature)) false - else if (ctx.importInfo.originals.contains(feature)) true + if (ctx.importInfo eq null) false else { - var c = ctx.outer - while (c.importInfo eq ctx.importInfo) c = c.outer - hasImport(c) + val isImportOwner = ctx.importInfo.site.widen.typeSymbol eq owner + if (isImportOwner && ctx.importInfo.originals.contains(feature)) true + else if (isImportOwner && ctx.importInfo.excluded.contains(feature)) false + else { + var c = ctx.outer + while (c.importInfo eq ctx.importInfo) c = c.outer + hasImport(c) + } } } def hasOption = ctx.base.settings.language.value exists (s => s == featureName || s == "_") diff --git a/tests/neg/dynamicNoImport.scala b/tests/neg/dynamicNoImport.scala index c009d91a43d0..ca12706735fa 100644 --- a/tests/neg/dynamicNoImport.scala +++ b/tests/neg/dynamicNoImport.scala @@ -9,5 +9,10 @@ package A { class Foo extends scala.Dynamic // error trait Bar extends scala.Dynamic // error object Baz extends scala.Dynamic // error + + package C { + import scala.language.{ dynamics => d } + class Foo extends scala.Dynamic // OK + } } } diff --git a/tests/neg/i3736b.scala b/tests/neg/i3736b.scala new file mode 100644 index 000000000000..adb3ce49bb88 --- /dev/null +++ b/tests/neg/i3736b.scala @@ -0,0 +1,7 @@ +import foo.dynamics + +class Foo() extends Dynamic // error: extension of type scala.Dynamic needs to be enabled + +package foo { + class dynamic +} diff --git a/tests/pos/i3736.scala b/tests/pos/i3736.scala new file mode 100644 index 000000000000..3f859c29dc28 --- /dev/null +++ b/tests/pos/i3736.scala @@ -0,0 +1,3 @@ +import scala.language.dynamics +import scala.Nil +class Foo() extends Dynamic