From 80d6407def59d1755adfa25a99bfe3caca595681 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Aug 2022 16:12:15 +0200 Subject: [PATCH 1/5] Allow for importing methods Importing individual methods didn't work as advertised because parser would allow them but later drop that information. --- .../main/scala/org/enso/syntax/text/AST.scala | 12 ++++++------ .../enso/syntax/text/ast/meta/Builtin.scala | 19 +++++++++---------- 2 files changed, 15 insertions(+), 16 deletions(-) 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..d0d021e398db 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) } + def 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,13 @@ object Builtin { case Match.Or(_, Left(hidden)) => val hiddenItems = hidden.toStream .map(_.wrapped) - .flatMap(AST.Ident.Cons.any.unapply) + .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 +344,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 } From d6d12d2a25f9d0feba4d5f79a70a10f93300764a Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Aug 2022 16:17:45 +0200 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) 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) From f604e0e739f07631e795edc1a77aa883f93b6ecc Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Thu, 4 Aug 2022 16:46:10 +0200 Subject: [PATCH 3/5] nit --- .../src/main/scala/org/enso/syntax/text/ast/meta/Builtin.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d0d021e398db..253b2c764eff 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,7 +289,7 @@ object Builtin { (name, rename) } - def consOrVar: PartialFunction[AST, AST.Ident] = { + val consOrVar: PartialFunction[AST, AST.Ident] = { case AST.Ident.Var.any(v) => v: AST.Ident case AST.Ident.Cons.any(c) => c: AST.Ident } From dfcf2e8df3c2fb78220cf3c7c8b6bbaef48ce1bc Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 5 Aug 2022 10:33:39 +0200 Subject: [PATCH 4/5] Add some tests --- .../test/scala/org/enso/compiler/test/codegen/AstToIrTest.scala | 2 ++ .../src/main/scala/org/enso/syntax/text/ast/meta/Builtin.scala | 1 + 2 files changed, 3 insertions(+) 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/meta/Builtin.scala b/lib/scala/syntax/definition/src/main/scala/org/enso/syntax/text/ast/meta/Builtin.scala index 253b2c764eff..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 @@ -310,6 +310,7 @@ object Builtin { case Match.Or(_, Left(hidden)) => val hiddenItems = hidden.toStream .map(_.wrapped) + .drop(2) .collect(consOrVar) (List1(hiddenItems), None) From 095119584c553da97521883aec74a8da96ee6560 Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 5 Aug 2022 17:00:03 +0200 Subject: [PATCH 5/5] fix broken test --- test/Tests/src/Semantic/Names_Spec.enso | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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