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

Allow for importing methods #3633

Merged
merged 8 commits into from Aug 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Expand Up @@ -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"
Expand Down
Expand Up @@ -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],
Expand Down Expand Up @@ -2395,17 +2395,17 @@ 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[
(
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 =>
Expand Down
Expand Up @@ -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(","))
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion 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

Expand Down