Skip to content

Preserve the declared type name in mismatch errors#5682

Draft
OceanOak wants to merge 3 commits into
darklang:mainfrom
OceanOak:type-error
Draft

Preserve the declared type name in mismatch errors#5682
OceanOak wants to merge 3 commits into
darklang:mainfrom
OceanOak:type-error

Conversation

@OceanOak

@OceanOak OceanOak commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

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*.ParseError family, 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 ...

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.

1 participant