Repository navigation
infer: unsafe mark kept on rewritten calls, a hidden class method is an error, das-fmt glue - #4911
Merged
Merged
Conversation
The rule that spaces a cast from its operand left a plain dot alone after type<T>, but still put a space before ?. , !. and !?. , and kept a space a writer had left before the dot. A member access of any of the four spellings is now glued to the type expression. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
unsafe(expr) marks expr with alwaysSafe and userSaidItsSafe. Six rewrites copied only alwaysSafe to the node they put in its place: a dot call into a plain call, a call in a method into a method call or a class function call, an overloaded [] and a binary operator into their functions, and pointer arithmetic into its call. The lint pass counts an unsafe only when both flags are set, so under the no_unsafe policy unsafe(obj.f()), unsafe(Class.f()), unsafe(a[i]) with an overloaded [] and unsafe(f()) inside a method compiled. Each rewrite now copies the whole flag set of the node it replaces. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A static call through a class name is spelled with _:: when the code being inferred cannot see the class's module - a generic of one module instanced in another for a class of a third. That search covers every module the program sees. A plain function of another class of the same name was already refused, but a generic static method was accepted unchecked, so the more specialized generic of the other class was called with no error. The check now runs before the lookup, over every function and generic the name and the arguments match: when one belongs to another class, the call is an error that says the static method is hidden. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Four functions walked a class's module tables by name hash and checked classParent: Structure::hasUserConstructor, hasUserDefaultConstructor and hasUserFinalizer, and the helper inference used for super calls and static methods. They are now Structure::hasOwnFunction with the test each one applies. The two walks up the parent chain for a user constructor and a user finalizer share one template. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A documented nit remains unresolved: top-level //! comments immediately before a top-level def in tests/language/uncategorized_no_aot.das:309 won’t attach as intended and should be adjusted per the stated comment-hygiene guidance.
1 open issue
What changed in this PR
Tightens inference and formatting behavior by preserving generation/unsafe flags across call rewrites, rejecting ambiguous static calls through a class name when another same-named class could answer, and fixing das-fmt spacing around member access on type<...> expressions.
Changes:
- Copy full
genFlagswhen rewriting call/operator nodes sono_unsafeenforcement can’t be bypassed by rewrites. - Error on
Class.method(...)when a different same-named class can also match (addsanotherClassAnswersand fixtures). - Glue member-access operators (
.,?.,!.,!?.) to type expressions indas-fmtand extend formatter tests. - Refactor repeated structure-function lookups via
Structure::hasOwnFunctionand update documentation.
| File | Description |
|---|---|
| tests/language/uncategorized_no_aot.das | Adds a regression test harness/fixture to ensure rewritten calls preserve unsafe(...) marks under the no_unsafe policy. |
| tests/language/failed_static_dot_generic_hidden.das | Introduces a compile-fail test that asserts an error for ambiguous static calls through a class name when another same-named class could answer. |
| tests/language/_static_member_other.das | Adds a helper module defining the “other” same-named class used to reproduce the hidden/ambiguous static-member resolution case. |
| tests/language/_static_member_helper.das | Extends the static-member helper with a generic/utility used by the new hidden-class ambiguity fixture. |
| tests/daslib/test_format.das | Extends formatter tests to verify member-access operators remain glued after type<...> expressions (including ?., !., and !?.). |
| tests/aot/CMakeLists.txt | Registers the new underscore-prefixed helper module so it is included in AOT builds/tests. |
| src/ast/ast.cpp | Adds Structure::hasOwnFunction and refactors constructor/finalizer-related checks to reuse the shared lookup helper. |
| src/ast/ast_infer_type.h | Declares the anotherClassAnswers helper used to detect ambiguous static call-through-class-name cases. |
| src/ast/ast_infer_type.cpp | Implements the static-call ambiguity check and updates multiple rewrite sites to preserve original genFlags on replacement nodes. |
| src/ast/ast_infer_type_op.cpp | Updates operator-to-call rewriting to copy genFlags from the source node rather than relying on narrower safety flags. |
| src/ast/ast_generate.cpp | Refactors shared ancestor/search logic used in generation-related structural checks. |
| src/ast/ARCHITECTURE_STATIC_MEMBERS.md | Updates the static-member-dot documentation to reflect the stricter ambiguity/error behavior and the new helper logic. |
| include/daScript/ast/ast.h | Exposes the new Structure::hasOwnFunction API in the public AST header. |
| daslib/das_source_formatter.das | Adjusts formatting rules to remove spaces and keep member-access tokens glued to preceding type/cast expressions. |
Review effort: Balanced
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
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.

Behavior change: under the
no_unsafepolicy,unsafe(...)around a dot call, a class-name call, an overloaded[]or a call inside a method is now rejected - hosts with that policy must drop theunsafe.Why. Those four shapes compiled under
no_unsafe: the rewrite of the call dropped the mark the policy reads. A generic static method of another same-named class could answerClass.f()with no error.das-fmtput a space intype<T>?.x.What changes.
das-fmtglues.,?.,!.and!?.to a type expression.Structure::hasOwnFunctionreplaces four copies of one lookup.Observable behavior.
unsafe(h.value_of())underno_unsafe-> error 31012 (compiled before).type<T>.pick(x)in a generic of another module, beside a same-named class -> error 30341 (called the other class before).type<Foo> .count,type<Foo>?.count-> formatted glued.Where to look.
anotherClassAnswersand its call in the static loop ofInferTypes::visit(ExprInvoke*); the flag copies are one line each.Validation, claims, ledger
Validation
test_aotlane green on the head commit8b957a8f30(preflighttests-aotrun alone, Linux, LLVM on). With all eight lanes sharing the box the same lane had one red,tests/lint/test_parallel_equivalence.dasat 65.9 s against the 60 s per-file limit; alone that file passes in 12.4 s. The interpreter, JIT, tests-cpp, watchdog and utils suites are green on the same head.tutorial recording is not stagedwarnings; staging needs GitHub credentials the box does not have.unsafeshapes compile under the policy, and the hidden-method fixture prints the other class's answer.unsafetest on their own; the fourth is the refactor.src/ast/ARCHITECTURE_STATIC_MEMBERS.md#static-member-dotmatches the code at its new citeranotherClassAnswers.Claims - stated, not tested
unsafe(a + b)with an overloaded+was already rejected under the policy, so no test tells its rewrite site's flag copy apart; the pointer-arithmetic site was not probed.Not done