Skip to content

Fix #3736: Fix owner checking logic #3739

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 4 commits into from
Jan 4, 2018
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
22 changes: 14 additions & 8 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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 == "_")
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/dynamicNoImport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
7 changes: 7 additions & 0 deletions tests/neg/i3736b.scala
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions tests/pos/i3736.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import scala.language.dynamics
import scala.Nil
class Foo() extends Dynamic