Preserve the declared type name in mismatch errors#5682
Draft
OceanOak wants to merge 3 commits into
Draft
Conversation
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.
This PR fixes type-mismatch errors that showed the wrong expected type name. The expected type was rendered from its ValueType, which keeps only the package content hash; for structurally-identical package types, such as the
Int*.ParseErrorfamily, that could display a canonical sibling instead of the referenced package type.The fix carries the resolved package location from PT into RT custom type references and stores it on
FnParameterNotExpectedType /FnResultNotExpectedType. The pretty-printer uses that location when rendering the expected type, while preserving the normal ValueType rendering for type arguments and fallback cases.To test it:
./scripts/run-cli fn '/Darklang.Stdlib.Test.ppErrTest' '(e: Stdlib.Int16.ParseError): String = "ok"'./scripts/run-cli eval 'Stdlib.Test.ppErrTest 5L'Before:
expects Darklang.Stdlib.Int128.ParseError, but got Int64 (5)After:
expects Stdlib.Int16.ParseError, but got Int64 (5)It also fixes the same problem for function names.
To test it:
./scripts/run-cli fn '/Darklang.Stdlib.Int128.ppErrTest' '(e: Stdlib.Int16.ParseError): String = "ok"'./scripts/run-cli fn '/Darklang.Stdlib.Test.ppErrTest' '(e: Stdlib.Int16.ParseError): String = "ok"'./scripts/run-cli eval 'Stdlib.Test.ppErrTest 5L'(identical bodies → same hash, so the two names collapse to one function)
Before:
Darklang.Stdlib.Int128.ppErrTest's 1st parameter ...After:
Darklang.Stdlib.Test.ppErrTest's 1st parameter ...