diff --git a/CHANGELOG.md b/CHANGELOG.md index 6614d95fb88f..ba4c6b150688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -302,6 +302,7 @@ - [Explicit `self`][3569] - [Added benchmarking tool for the language server][3578] - [Support module imports using a qualified name][3608] +- [Support importing module methods][3633] [3227]: https://github.com/enso-org/enso/pull/3227 [3248]: https://github.com/enso-org/enso/pull/3248 @@ -338,6 +339,7 @@ [3538]: https://github.com/enso-org/enso/pull/3569 [3578]: https://github.com/enso-org/enso/pull/3578 [3608]: https://github.com/enso-org/enso/pull/3608 +[3633]: https://github.com/enso-org/enso/pull/3633 # Enso 2.0.0-alpha.18 (2021-10-12) diff --git a/engine/runtime/src/test/scala/org/enso/compiler/test/codegen/AstToIrTest.scala b/engine/runtime/src/test/scala/org/enso/compiler/test/codegen/AstToIrTest.scala index 497a9758573b..bbd2467a7938 100644 --- a/engine/runtime/src/test/scala/org/enso/compiler/test/codegen/AstToIrTest.scala +++ b/engine/runtime/src/test/scala/org/enso/compiler/test/codegen/AstToIrTest.scala @@ -1048,6 +1048,8 @@ class AstToIrTest extends CompilerTest with Inside { "from project import all", "from Username.Bar.Quux import Baz", "from Username.Bar.Test import Baz, Spam", + "from Username.Bar.Test import Baz, Spam, foo, Bar", + "from Username.Bar.Test import foo, bar", "from username.Foo.Bar import all", "from username.Foo.Bar as Eggs import all hiding Spam", "from project.Foo.Bar import all hiding Spam, Eggs" diff --git a/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/AST.scala b/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/AST.scala index c82fca91faa2..ff8633c65a37 100644 --- a/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/AST.scala +++ b/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/AST.scala @@ -345,8 +345,8 @@ object Shape extends ShapeImplicit { path: List1[AST.Ident], rename: Option[AST.Ident.Cons], isAll: Boolean, - onlyNames: Option[List1[AST.Ident.Cons]], - hidingNames: Option[List1[AST.Ident.Cons]] + onlyNames: Option[List1[AST.Ident]], + hidingNames: Option[List1[AST.Ident]] ) extends SpacelessAST[T] final case class Export[T]( path: List1[AST.Ident], @@ -2395,8 +2395,8 @@ object AST { path: List1[AST.Ident], rename: Option[AST.Ident.Cons], isAll: Boolean, - onlyNames: Option[List1[AST.Ident.Cons]], - hidingNames: Option[List1[AST.Ident.Cons]] + onlyNames: Option[List1[AST.Ident]], + hidingNames: Option[List1[AST.Ident]] ): Import = Shape.Import[AST](path, rename, isAll, onlyNames, hidingNames) def unapply(t: AST): Option[ @@ -2404,8 +2404,8 @@ object AST { List1[AST.Ident], Option[AST.Ident.Cons], Boolean, - Option[List1[AST.Ident.Cons]], - Option[List1[AST.Ident.Cons]] + Option[List1[AST.Ident]], + Option[List1[AST.Ident]] ) ] = Unapply[Import].run(t => diff --git a/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/ast/meta/Builtin.scala b/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/ast/meta/Builtin.scala index 33668cf74b7a..6a316f4495a4 100644 --- a/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/ast/meta/Builtin.scala +++ b/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/ast/meta/Builtin.scala @@ -289,6 +289,11 @@ object Builtin { (name, rename) } + val consOrVar: PartialFunction[AST, AST.Ident] = { + case AST.Ident.Var.any(v) => v: AST.Ident + case AST.Ident.Cons.any(c) => c: AST.Ident + } + val itemsImport = { val all: Pattern = Var("all") val items = Pattern.SepList(Pattern.Cons() | Pattern.Var(), Opr(",")) @@ -305,13 +310,14 @@ object Builtin { case Match.Or(_, Left(hidden)) => val hiddenItems = hidden.toStream .map(_.wrapped) - .flatMap(AST.Ident.Cons.any.unapply) + .drop(2) + .collect(consOrVar) (List1(hiddenItems), None) case Match.Or(_, Right(imported)) => val importedItems = imported.toStream .map(_.wrapped) - .flatMap(AST.Ident.Cons.any.unapply) + .collect(consOrVar) (None, List1(importedItems)) case _ => internalError } @@ -339,19 +345,13 @@ object Builtin { val hiddenItems = hidden.toStream .map(_.wrapped) .drop(2) - .collect { - case AST.Ident.Var.any(v) => v: AST.Ident - case AST.Ident.Cons.any(c) => c: AST.Ident - } + .collect(consOrVar) (List1(hiddenItems), None) case Match.Or(_, Right(imported)) => val importedItems = imported.toStream .map(_.wrapped) - .collect { - case AST.Ident.Var.any(v) => v: AST.Ident - case AST.Ident.Cons.any(c) => c: AST.Ident - } + .collect(consOrVar) (None, List1(importedItems)) case _ => internalError } diff --git a/test/Tests/src/Semantic/Names_Spec.enso b/test/Tests/src/Semantic/Names_Spec.enso index ea39abe5f874..5a508cc61094 100644 --- a/test/Tests/src/Semantic/Names_Spec.enso +++ b/test/Tests/src/Semantic/Names_Spec.enso @@ -1,6 +1,7 @@ from Standard.Base import all -from project.Semantic.Names.Definitions import another_method, another_constant, method_with_local_vars +from project.Semantic.Names.Definitions import another_method, another_constant, method_with_local_vars, Bar +import project.Semantic.Names.Definitions import Standard.Test