fix(typecheck): check enum variant constructor arguments against their payload - #148
Merged
Merged
Conversation
…r payload
.Circle("x") and Shape.Circle("x") into a num payload, or a wrong number of arguments, were accepted and only surfaced (if at all) as a C compile error. A shared check now holds a constructor's argument count and each argument's type to the declared payload, in both the shorthand and the qualified form, with a generic enum's parameters (defaults included) replaced by what the expected type instantiated them as. A nested shorthand in an argument is held to that slot's own enum.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
ret .Circle("x"),ret Shape.Circle("x"),ret .Rect(1)(too few) andret Shape.Circle(1, 2)(too many) were all accepted by typecheck. The checker only validated a shorthand's variant name and any nested shorthand, never the constructor's argument count or types.check_variant_args) now holds a constructor's count and each argument's type to the declared payload, for both the shorthand and the qualified form. A generic enum's parameters, defaults included, are replaced by what the expected type instantiated them as:.Err(1)where aRes<num>is expected reportsargument 1 of variant 'Err' of 'Res' expects str, found num. A parameter the expected type does not resolve stands for anything, and a nested shorthand is held to its slot's own enum.Shape s = Shape.Circle("x")) is checked with no expected type.Test plan
fun test .33/33 files,fun -fmt-check-allclean,fun lint srccleanscripts/run_examples.sh218/218 (known pre-existinglet_and_lowlevel_types.fnflake)