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

feat(compiler): Providing, including, reproviding exceptions #1849

Merged
merged 4 commits into from
Jan 28, 2024

Conversation

alex-snezhko
Copy link
Member

Closes #1053

Syntax:

// provider.gr
provide exception MyException
// OR
exception MyException
provide { exception MyException }

// includer.gr
include "./provider"
from Provider use { exception MyException }
// can re-provide
provide { exception MyException }

Copy link
Member

@spotandjake spotandjake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just had one small nit.

@@ -11,7 +11,7 @@ include /* special include */ "array"
include "array" as /* special include */ Foo
from List use { length, map, forEach as each }
from Opt use { MutableOpt, ImmutableOpt as Imm, type Opt, type Opt as OptAlias }
from Opt use { MutableOpt, /* comment1 */ ImmutableOpt /* comment2 */ as /* comment3 */ Imm /* comment4 */, /* comment5 */ type /* comment6 */ Opt, type Opt as /* comment7 */ OptAlias }
from Opt use { MutableOpt, /* comment1 */ ImmutableOpt /* comment2 */ as /* comment3 */ Imm /* comment4 */, /* comment5 */ type /* comment6 */ Opt, type Opt as /* comment7 */ OptAlias, exception Exc as /* comment8 */ E }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness and to follow the rest it would probably make sense to add the test here without as as well to mirror the variable and type import.

Suggested change
from Opt use { MutableOpt, /* comment1 */ ImmutableOpt /* comment2 */ as /* comment3 */ Imm /* comment4 */, /* comment5 */ type /* comment6 */ Opt, type Opt as /* comment7 */ OptAlias, exception Exc as /* comment8 */ E }
from Opt use { MutableOpt, /* comment1 */ ImmutableOpt /* comment2 */ as /* comment3 */ Imm /* comment4 */, /* comment5 */ type /* comment6 */ Opt, type Opt as /* comment7 */ OptAlias, , exception /* comment8 */ Exc, exception Exc as /* comment9 */ E }

Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some tests where you provide an exception + a value of that exception and then successfully pattern match on it in the consuming module? Just want to make sure that works.

Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo @ospencer's test request

@spotandjake
Copy link
Member

spotandjake commented Jun 12, 2023

as exceptions behave a little differently then most types. in that the value is based off the type. so if you did

exception F
print(F) // F

when you use the from syntax with as. you could do

from Module use { exception F as Y }

print(Y) // F

I feel like this might be a little confusing the closest analogy I can think of would be if we allowed enum aliasing, you could do something like print(Enum.North) and get South as the printed value.

I wonder if we want to allow aliasing exceptions.

Cut down version of message sent in discord.

Also we should add a test for throw Module.Exception with the Module. syntax rather than just using the from syntax.

Copy link
Member

@marcusroberts marcusroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks useful to me and good syntax.

@ospencer ospencer added this pull request to the merge queue Jan 28, 2024
Merged via the queue into grain-lang:main with commit 687e747 Jan 28, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot re-export an exception
5 participants