Skip to content
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

from/all import must not include module in name resolution #3931

Merged
merged 7 commits into from
Nov 30, 2022
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@
- [Support VCS for projects in Language Server][3851]
- [Support multiple exports of the same module][3897]
- [Don't export polyglot symbols][3915]
- [From/all import must not include module in name resolution][3931]

[3227]: https://github.com/enso-org/enso/pull/3227
[3248]: https://github.com/enso-org/enso/pull/3248
Expand Down Expand Up @@ -526,6 +527,7 @@
[3851]: https://github.com/enso-org/enso/pull/3851
[3897]: https://github.com/enso-org/enso/pull/3897
[3915]: https://github.com/enso-org/enso/pull/3915
[3931]: https://github.com/enso-org/enso/pull/3931

# Enso 2.0.0-alpha.18 (2021-10-12)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import project.Random
import project.Runtime.Ref.Ref

from project.Data.Boolean import Boolean, True, False
from project.Data.Range import Range
from project.Data.Range import all
from project.Error.Common import Error, Panic, Index_Out_Of_Bounds_Error_Data, Illegal_Argument_Error_Data

type Index_Sub_Range
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from Standard.Base import all hiding First, Last

import Standard.Table.Data.Aggregate_Column.Aggregate_Column
from Standard.Table.Data.Aggregate_Column.Aggregate_Column import all

import project.Data.Dialect.Dialect
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from Standard.Base import all hiding First, Last
import Standard.Base.Error.Common as Errors

import Standard.Table.Data.Aggregate_Column.Aggregate_Column
from Standard.Table.Data.Aggregate_Column.Aggregate_Column import all

import project.Data.SQL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from Standard.Base import all hiding First, Last

import Standard.Table.Data.Aggregate_Column.Aggregate_Column
from Standard.Table.Data.Aggregate_Column.Aggregate_Column import all

import project.Data.SQL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import project.Internal.Problem_Builder.Problem_Builder
import project.Internal.Table_Helpers
import project.Internal.Unique_Name_Strategy.Unique_Name_Strategy

import Standard.Table.Data.Aggregate_Column.Aggregate_Column
from project.Data.Aggregate_Column.Aggregate_Column import all
import project.Data.Table.Table
from project.Errors import Missing_Input_Columns_Data, Column_Indexes_Out_Of_Range, No_Output_Columns, Duplicate_Output_Column_Names_Data, Invalid_Output_Column_Names_Data, Invalid_Aggregation_Data, Floating_Point_Grouping_Data, Unquoted_Delimiter_Data, Additional_Warnings_Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -968,12 +968,12 @@ class RuntimeErrorsTest
val requestId = UUID.randomUUID()
val moduleName = "Enso_Test.Test.Main"
val metadata = new Metadata
val xId = metadata.addItem(49, 7)
val yId = metadata.addItem(65, 5)
val mainResId = metadata.addItem(75, 12)
val xId = metadata.addItem(40, 7)
val yId = metadata.addItem(56, 5)
val mainResId = metadata.addItem(66, 12)

val code =
"""from Standard.Base.IO import all
"""import Standard.Base.IO
|
|main =
| x = 1 + foo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,7 @@ class RuntimeServerTest
| 10.overloaded x
| Nothing.Nothing
|
|Text.Text.overloaded arg = arg + 1
|Text.overloaded arg = arg + 1
|Number.overloaded arg = arg + 2
|""".stripMargin.linesIterator.mkString("\n")
val contents = metadata.appendToCode(code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ case class BindingsMap(
private def importMatchesName(imp: ResolvedImport, name: String): Boolean = {
imp.importDef.onlyNames
.map(_ => imp.importDef.rename.exists(_.name == name))
.getOrElse(imp.importDef.getSimpleName.name == name)
.getOrElse(
!imp.importDef.isAll && imp.importDef.getSimpleName.name == name
)
}

private def findExportedCandidatesInImports(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Test_Import_Case
license: APLv2
enso-version: default
version: "0.0.1"
author: "Enso Team <contact@enso.org>"
maintainer: "Enso Team <contact@enso.org>"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type Atom
Value a b

new x y = Atom.Value x y
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from project.Atom import all

main =
x = Atom.new 1 2

case x of
_ : Atom -> 0
_ -> 1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ class ImportsTest extends PackageTest {
.filterNot(_.contains("Compiler encountered"))
.filterNot(_.contains("In module"))
.head should include("The name `Atom` could not be found.")
}

"Importing everything from the module" should "should not bring module into the scope when resolving names" in {
evalTestProject("Test_Import_Case") shouldEqual 0
}

"Exports system" should "detect cycles" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class InteropTest extends InterpreterTest {
val code =
"""from Standard.Base.Data.Any import all
|
|Any.Any.method self = self
|Any.method self = self
|
|main = x -> .method
|""".stripMargin
Expand All @@ -61,7 +61,7 @@ class InteropTest extends InterpreterTest {
|from Standard.Base.Data.Text import all
|
|Number.add self x = x + self
|Text.Text.add self x = self + x
|Text.add self x = self + x
|
|main = .add
|""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class LambdaTest extends InterpreterTest {

"call fully saturated returned lambdas" in {
val code =
"""from Standard.Base.IO import all
"""import Standard.Base.IO
|
|main =
| fn = a -> b ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MethodsTest extends InterpreterTest {

"execute `self` argument once" in {
val code =
"""from Standard.Base.IO import all
"""import Standard.Base.IO
|import Standard.Base.Nothing
|
|Nothing.Nothing.foo = 0
Expand Down Expand Up @@ -90,7 +90,7 @@ class MethodsTest extends InterpreterTest {
val code =
"""from Standard.Base.Data.Any import all
|
|Any.Any.method self =
|Any.method self =
| x = self * self
| y = x * 2
| y + 1
Expand Down Expand Up @@ -120,7 +120,7 @@ class MethodsTest extends InterpreterTest {
|type Bar
|type Baz
|
|Any.Any.method self = case self of
|Any.method self = case self of
| Foo -> 1
| Bar -> 2
| Baz -> 3
Expand Down Expand Up @@ -167,7 +167,7 @@ class MethodsTest extends InterpreterTest {

"be callable on types when non-static, with additional self arg" in {
val code =
"""from Standard.Base.IO import all
"""import Standard.Base.IO
|
|type Foo
| Mk_Foo a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ class PolyglotTest extends InterpreterTest {
count shouldEqual "FAIL"
}

"fail to match on Polyglot type when explicitly importing everything from Polyglot module" in {
"match on Polyglot type when explicitly importing everything from Polyglot module" in {
val code =
"""from Standard.Base.Polyglot import all
|from Standard.Base.IO import all
|import Standard.Base.IO
|polyglot java import java.util.Random
|
|main =
Expand All @@ -139,13 +139,13 @@ class PolyglotTest extends InterpreterTest {
|""".stripMargin
eval(code)
val count :: Nil = consumeOut
count shouldEqual "FAIL"
count shouldEqual "OK"
}

"fail to match on Polyglot type case when only importing Polyglot module" in {
val code =
"""import Standard.Base.Polyglot
|from Standard.Base.IO import all
|import Standard.Base.IO
|polyglot java import java.util.Random
|
|main =
Expand All @@ -162,7 +162,7 @@ class PolyglotTest extends InterpreterTest {
"match on qualified name of the Polyglot type from Polyglot module" in {
val code =
"""import Standard.Base.Polyglot
|from Standard.Base.IO import all
|import Standard.Base.IO
|polyglot java import java.util.Random
|
|main =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RuntimeManagementTest extends InterpreterTest {

val code =
"""import Standard.Base.Runtime.Thread
|from Standard.Base.IO import all
|import Standard.Base.IO
|import Standard.Base.Nothing
|
|foo x =
Expand Down Expand Up @@ -92,7 +92,7 @@ class RuntimeManagementTest extends InterpreterTest {
val code =
"""
|from Standard.Base.Runtime.Resource import Managed_Resource
|from Standard.Base.IO import all
|import Standard.Base.IO
|
|type Mock_File
| Value i
Expand Down Expand Up @@ -124,7 +124,7 @@ class RuntimeManagementTest extends InterpreterTest {
val code =
"""
|from Standard.Base.Runtime.Resource import Managed_Resource
|from Standard.Base.IO import all
|import Standard.Base.IO
|import Standard.Base.Nothing
|
|type Mock_File
Expand Down Expand Up @@ -158,7 +158,7 @@ class RuntimeManagementTest extends InterpreterTest {
val code =
"""
|from Standard.Base.Runtime.Resource import Managed_Resource
|from Standard.Base.IO import all
|import Standard.Base.IO
|import Standard.Base.Nothing
|
|type Mock_File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BooleanTest extends InterpreterTest {
"support if_then_else" in {
val code =
"""from Standard.Base.Data.Boolean import all
|from Standard.Base.IO import all
|import Standard.Base.IO
|
|main =
| if True then IO.println "true when true" else IO.println "false when true"
Expand All @@ -25,9 +25,9 @@ class BooleanTest extends InterpreterTest {
"support overriding methods on boolean" in {
val code =
"""from Standard.Base.Data.Boolean import all
|from Standard.Base.IO import all
|import Standard.Base.IO
|
|Boolean.Boolean.isTrue self = self
|Boolean.isTrue self = self
|
|main =
| true = 1 == 1
Expand Down Expand Up @@ -57,7 +57,7 @@ class BooleanTest extends InterpreterTest {
"support logical AND and OR operators" in {
val code =
"""from Standard.Base.Data.Boolean import all
|from Standard.Base.IO import all
|import Standard.Base.IO
|
|main =
| IO.println True&&False
Expand All @@ -73,7 +73,7 @@ class BooleanTest extends InterpreterTest {
"support negation" in {
val code =
"""from Standard.Base.Data.Boolean import all
|from Standard.Base.IO import all
|import Standard.Base.IO
|
|main =
| IO.println True.not
Expand Down