Skip to content

refactor(compiler): improve clarity of common type error messages#1536

Open
sqrew wants to merge 8 commits into
carp-lang:masterfrom
sqrew:fix/compiler-error-message-refinement
Open

refactor(compiler): improve clarity of common type error messages#1536
sqrew wants to merge 8 commits into
carp-lang:masterfrom
sqrew:fix/compiler-error-message-refinement

Conversation

@sqrew
Copy link
Copy Markdown
Contributor

@sqrew sqrew commented Apr 16, 2026

This PR refines several common error messages in the Carp compiler to make them more helpful and direct for developers.

Changes:

  • Unification Errors: Added a 'Type mismatch' prefix to UnificationFailed errors to make the issue immediately obvious.
  • Reference Returns: Updated FunctionsCantReturnRefTy and LetCantReturnRefTy to provide clearer advice on fixing the issue by using @ (copy) or returning owned values.
  • Unknown Types: Improved NotAType and NotAmongRegisteredTypes to include a hint about using register-type for external C types.

Disclaimer: This PR was built with the assistance of Gemini (an AI assistant) working in collaboration with @sqrew to improve the Carp compiler's user experience.

- Enhanced UnificationFailed with 'Type mismatch' prefix
- Clarified reference return errors with advice on using '@' or owned values
- Improved NotAType and NotAmongRegisteredTypes with advice for external types
- Refined wording for better developer experience
@sqrew sqrew force-pushed the fix/compiler-error-message-refinement branch from 6e6cf90 to ceb4787 Compare April 16, 2026 17:24
Copy link
Copy Markdown
Member

@hellerve hellerve left a comment

Choose a reason for hiding this comment

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

You’ll also have to update machineReadableErrorStrings.

sqrew added 2 commits April 25, 2026 18:33
- Aligned machineReadableErrorStrings with Show instance refinements.
- Added suggestions and context to common type error messages.
- Verified successful compiler build.
- Updated machineReadableErrorStrings to align with Show instance.
- Restored original variable name resolution in UsingDeadReference.
- Added memStateNames to MemState to support variable name tracking.
- Synced all expected error outputs in test suite.
- Verified all core and error tests passing.
Copy link
Copy Markdown
Member

@hellerve hellerve left a comment

Choose a reason for hiding this comment

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

Some small comments. The memStateNames situation deserves a second look, methinks.

Comment thread src/Memory.hs
memStateLifetimes :: Map.Map String LifetimeMode,
memStateParamDeleters :: Set.Set Deleter
memStateParamDeleters :: Set.Set Deleter,
memStateNames :: Map.Map String String
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don’t think this does anything unless we key by varOfXObj name. Check

(defn main []
    (let [my-var (the (Array Int) [1 2 3])
          r (ref my-var)]
      (do (delete my-var)
          (println* (the &(Array Int) r)))))

You’ll get my_MINUS_var.

Comment thread src/TypeError.hs Outdated
[machineReadableInfoFromXObj fppl xobj ++ " The reference '" ++ pretty xobj ++ "' isn't alive."]
(UsingDeadReference xobj _ _) ->
[machineReadableInfoFromXObj fppl xobj ++ " The reference '" ++ pretty xobj ++ "' is no longer valid."]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Stray blank line?

Comment thread src/TypeError.hs
"I encountered a definition that was not at top level: `" ++ pretty xobj ++ "`"
show (UsingDeadReference xobj dependsOn) =
"The reference '" ++ pretty xobj ++ "' (depending on the variable '" ++ dependsOn ++ "') isn't alive at " ++ prettyInfoFromXObj xobj ++ "."
show (UsingDeadReference xobj dependsOn originalName) =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should use either ' or `, not both.

Copy link
Copy Markdown
Member

@hellerve hellerve left a comment

Choose a reason for hiding this comment

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

Just two chunks that I believe are dead code, otherwise this now looks good to go!

Comment thread src/Memory.hs Outdated
Comment thread src/Memory.hs Outdated
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.

2 participants