-
Notifications
You must be signed in to change notification settings - Fork 269
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: namespace directive #5285
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!! That was fast.
I'm not sure why the transcript error message regression is happening. Though it might not matter too much if the only behavior is a worse error message in the event you call a definition namespace
. Still, would be nice to keep the good message.
Very cool! Can you have multiple namespace directives in a file? |
@hojberg You cannot – zero or one |
@pchiusano I looked into this briefly, it really isn't more complicated than we're now parsing |
@mitchellwrosen cool. Yeah I wouldn’t sweat it for this PR then. |
Overview
This PR implements the "namespace directive" feature: a Unison file can contain an optional
namespace foo
line that affects parsing as follows:That is,
is equivalent to
Note that the existence of a namespace directive therefore prevents one from referring to a name outside of the file whose suffix matches something in the file.
For example, without a namespace directive, I could write
and refer to both my locally-bound
foo.factorial
as well as a term literally namedfactorial
(no other prefix) in the namespace. (N.B that's not true in trunk today, but it will be fixed soon: #5268).However, with a namespace directive...
there's no way to write the same function (because
factorial
resolves to the locally-boundfactorial
, which will be expanded tofoo.factorial
during parsing).For this reason, it would be unsafe to implement
edit.namespace foo
naively by putting anamespace foo
directive at the top of the block.Test coverage
I've added a transcript to demonstrate the feature.