diff --git a/CHANGELOG.md b/CHANGELOG.md index d9cf94095d83..df3aa04c40bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Index_Sub_Range.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Index_Sub_Range.enso index f430d7580818..73ab48c8b7fd 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Index_Sub_Range.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Index_Sub_Range.enso @@ -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 diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Aggregate_Helper.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Aggregate_Helper.enso index 6e499bb9e468..ed828b864f67 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Aggregate_Helper.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Aggregate_Helper.enso @@ -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 diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Postgres/Postgres_Dialect.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Postgres/Postgres_Dialect.enso index 1fe78e0771d9..c70e69d9d077 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Postgres/Postgres_Dialect.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Postgres/Postgres_Dialect.enso @@ -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 diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/SQLite/SQLite_Dialect.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/SQLite/SQLite_Dialect.enso index 718cf26254b4..5796a670d507 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/SQLite/SQLite_Dialect.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/SQLite/SQLite_Dialect.enso @@ -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 diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso index 2f91d357e8dc..5b525239eba0 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso @@ -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 diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeErrorsTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeErrorsTest.scala index 99492819fc36..7a6ff5061e98 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeErrorsTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeErrorsTest.scala @@ -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 diff --git a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala index dc1cc4cab1e8..c42cafca2634 100644 --- a/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala +++ b/engine/runtime-with-instruments/src/test/scala/org/enso/interpreter/test/instrument/RuntimeServerTest.scala @@ -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) diff --git a/engine/runtime/src/main/scala/org/enso/compiler/data/BindingsMap.scala b/engine/runtime/src/main/scala/org/enso/compiler/data/BindingsMap.scala index 69ac7cd15220..7b27104f4c01 100644 --- a/engine/runtime/src/main/scala/org/enso/compiler/data/BindingsMap.scala +++ b/engine/runtime/src/main/scala/org/enso/compiler/data/BindingsMap.scala @@ -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( diff --git a/engine/runtime/src/test/resources/Test_Import_Case/package.yaml b/engine/runtime/src/test/resources/Test_Import_Case/package.yaml new file mode 100644 index 000000000000..6ce241770d55 --- /dev/null +++ b/engine/runtime/src/test/resources/Test_Import_Case/package.yaml @@ -0,0 +1,6 @@ +name: Test_Import_Case +license: APLv2 +enso-version: default +version: "0.0.1" +author: "Enso Team " +maintainer: "Enso Team " diff --git a/engine/runtime/src/test/resources/Test_Import_Case/src/Atom.enso b/engine/runtime/src/test/resources/Test_Import_Case/src/Atom.enso new file mode 100644 index 000000000000..f9ce691dd540 --- /dev/null +++ b/engine/runtime/src/test/resources/Test_Import_Case/src/Atom.enso @@ -0,0 +1,4 @@ +type Atom + Value a b + + new x y = Atom.Value x y diff --git a/engine/runtime/src/test/resources/Test_Import_Case/src/Main.enso b/engine/runtime/src/test/resources/Test_Import_Case/src/Main.enso new file mode 100644 index 000000000000..75c7bcfdabcd --- /dev/null +++ b/engine/runtime/src/test/resources/Test_Import_Case/src/Main.enso @@ -0,0 +1,8 @@ +from project.Atom import all + +main = + x = Atom.new 1 2 + + case x of + _ : Atom -> 0 + _ -> 1 diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/ImportsTest.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/ImportsTest.scala index a99d64504fa4..5fa3194cc342 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/ImportsTest.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/ImportsTest.scala @@ -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 { diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/InteropTest.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/InteropTest.scala index 827b467ccb8b..b1feb2c25b01 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/InteropTest.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/InteropTest.scala @@ -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 @@ -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 diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/LambdaTest.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/LambdaTest.scala index cff4ff0798fd..fede714582c6 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/LambdaTest.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/LambdaTest.scala @@ -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 -> diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/MethodsTest.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/MethodsTest.scala index c9f9cc275c25..7241eef7cde4 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/MethodsTest.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/MethodsTest.scala @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala index 6a1b67262f98..f007176fc3d3 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/PolyglotTest.scala @@ -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 = @@ -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 = @@ -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 = diff --git a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/RuntimeManagementTest.scala b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/RuntimeManagementTest.scala index f7b2212c8af0..7b03f019faf4 100644 --- a/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/RuntimeManagementTest.scala +++ b/engine/runtime/src/test/scala/org/enso/interpreter/test/semantic/RuntimeManagementTest.scala @@ -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 = @@ -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 @@ -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 @@ -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 diff --git a/engine/runtime/src/test/scala/org/enso/std/test/BooleanTest.scala b/engine/runtime/src/test/scala/org/enso/std/test/BooleanTest.scala index 7aa558364290..aa5f3cd5ec12 100644 --- a/engine/runtime/src/test/scala/org/enso/std/test/BooleanTest.scala +++ b/engine/runtime/src/test/scala/org/enso/std/test/BooleanTest.scala @@ -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" @@ -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 @@ -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 @@ -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