Expose the names of generated record constructors #6975
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The keyword
constructor
can appear as the last token in a qualified name, as long as it's the only name part. SoFoo.constructor
,Foo.Bar.constructor
are both valid, butconstructor
andFoo.constructor.bar
are still syntax errors.The
Foo.constructor
syntax is actual syntax. It looks like a name, but there's noconstructor
name in the moduleFoo
. That would be incorrect anyway, since the record module is parametrized by a value of the record type, but the constructor isn't; see #4189. Because of this, it's not possible to control the visibility ofFoo.constructor
: if you want that, give the constructor an actual name.If the constructor has a declared name, the
Foo.constructor
syntax is also disabled, with an error message explaining that the declared name should be used instead.To resolve
Foo.constructor
, we look upFoo
as an unambiguous record name, and then resolve to the actual name of the constructor, which is still kept internal. This means thatFoo.constructor
is in scope as long asFoo
is, so this doesn't reintroduce #282. It also means that renaming the record will also "rename" the constructor, as expected.