Skip to content

compiler: keep the C++ throw site out of user diagnostics (#557) - #573

Merged
ohohoreilly merged 1 commit into
masterfrom
ohohoreilly/557-clean-diagnostics
Oct 2, 2026
Merged

ohohoreilly merged 1 commit into
masterfrom
ohohoreilly/557-clean-diagnostics

Conversation

@ohohoreilly

Copy link
Copy Markdown
Member

Closes #557.

Before

$ orlyc -o . bad.orly
2:28-2:47 [orly/type/add_visitor.h, 50]This expression is invalid.

After

$ orlyc -o . bad.orly
2:28-2:47 The left side of a mutation must be a stored value, but this is an address. Name the value stored at it with `*` and its type, as in `*<['counter']>::(int) += n`.

What changed

  • TSourceError keeps the throw site as a field (GetCodeLocation()) instead of splicing it into what(). Every one of the ~2000 throw sites already passed the location as its own argument, so only error.h and the two print sites change.
    • orlyc --compiler-locations appends it. --debug/-d is taken, so this has its own flag.
    • WS source_error replies carry it in a separate compiler_loc key, so result is a clean message. This is documented in docs/PROTOCOL.md.
    • TImpossibleError keeps it in the message, now with a space after it. For an internal compiler error the location is the report.
  • The target of a mutation must now be a stored value. TMutate::TypeCheck checks this before running the operator's visitor:
    • A bare address gets the message above.
    • A plain value (x += n with x = 1) used to segfault orlyc with no output. On the released ghcr.io/orlyatomics/orly:latest it exits with code 139 and prints nothing. The crash is in TMutation::GetValType, which does As<TMutable>() on the target's type and dereferences the result unchecked. It now gets a clean error.
    • Sequences are excluded so they keep their existing diagnostic.

Tests

orlyc printed

    2:28-2:47 [orly/type/add_visitor.h, 50]This expression is invalid.

for a newcomer's `<['counter']> += n`. That is a path into the compiler's
own source, glued to the message with no space, and it reads like a crash.

TSourceError now keeps the TCodeLocation as a field instead of splicing it
into what(). orlyc shows it under --compiler-locations; WS source_error
replies carry it as a separate compiler_loc key. TImpossibleError keeps it
in the message, since for an internal compiler error the location is the
report.

TMutate::TypeCheck now requires the target to be a stored value. A bare
address used to fall through to the operator visitor's generic message; it
now names the problem and shows `*<['counter']>::(int) += n`. A plain value
(`x += n` with `x = 1`) used to segfault orlyc in TMutation::GetValType,
which dereferences the target's mutable type unchecked; it now gets a clean
error. Both are pinned by new diagnostic lang_tests, and the two baselines
that quoted a compiler path are updated.
@ohohoreilly ohohoreilly self-assigned this Oct 2, 2026
@ohohoreilly
ohohoreilly merged commit 1143a78 into master Oct 2, 2026
10 checks passed
@ohohoreilly
ohohoreilly deleted the ohohoreilly/557-clean-diagnostics branch October 2, 2026 02:55
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.

Compiler diagnostics leak internal C++ source paths to users ([orly/type/add_visitor.h, 50])

1 participant