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

Preserve empty variant constructor in data-deps. #7303

Merged
merged 3 commits into from
Sep 2, 2020

Conversation

sofiafaro-da
Copy link
Contributor

This fixes #7207 and adds a regression test. In a
separate PR I'll add a warning for variants with
single argument of unit type and add a changelog
entry.

changelog_begin
changelog_end

This fixes #7207 and adds a regression test. In a
separate PR I'll add a warning for variants with
single argument of unit type and add a changelog
entry.

changelog_begin
changelog_end
Copy link
Contributor

@cocreature cocreature left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -479,6 +479,9 @@ generateSrcFromLf env = noLoc mod

convConDetails :: LF.Type -> Gen (HsConDeclDetails GhcPs)
convConDetails = \case
-- empty variant constructor (see issue #7207)
LF.TUnit ->
Copy link
Contributor

Choose a reason for hiding this comment

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

This means that a variant where I explicilty specify a Unit argument will also be decompiled to a Prefix con right? I think that’s perfectly reasonable but probably worth documenting in a comment and perhaps warning on in the preprocessor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's what we decided on in the issue and I'm preparing the warning in a separate PR.

Copy link
Contributor

@hurryabit hurryabit left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks a lot!

We also need a changelog entry explaining how to migrate from the old world to the new world. We should also make it clear that this is a bug fix.

]
writeFileUTF8 (tmpDir </> "type" </> "Foo.daml") $ unlines
[ "module Foo where"
, "data A = B | C Int"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a third case D () and check that it behaves like D when imported as data-dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. D () is something we're deprecating, and the fact that it's treated the same as D in the current compiler is mostly a mistake.

Copy link
Contributor

Choose a reason for hiding this comment

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

I generally agree but would feel more comfortable to have a test as long as users can still write it, even though they get warned about it.

Copy link
Contributor Author

@sofiafaro-da sofiafaro-da Sep 2, 2020

Choose a reason for hiding this comment

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

I added a test for D () in the single constructor case, which is something we had talked about adding as a special case (since we can't distinguish single-constructor variants from enums any other way, and there's no ambiguity in the single constructor case). (This actually also came up in one of the other tests, but better to add one here as well.)

@@ -479,6 +479,9 @@ generateSrcFromLf env = noLoc mod

convConDetails :: LF.Type -> Gen (HsConDeclDetails GhcPs)
convConDetails = \case
-- empty variant constructor (see issue #7207)
Copy link
Contributor

Choose a reason for hiding this comment

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

"Empty" is such an overloaded word:

Suggested change
-- empty variant constructor (see issue #7207)
-- variant constructor without argument (see issue #7207)

Or "payload" instead of "argument".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, but "variant constructor without argument" is such a clumsy phrase, and what else could "empty variant constructor" mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the right answer here is "nullary variant constructor".

Copy link
Contributor

Choose a reason for hiding this comment

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

I like "nullary variant constructor". 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variant constructor matching (w/o argument) differs depending on package structure
3 participants