Skip to content

infer: unsafe mark kept on rewritten calls, a hidden class method is an error, das-fmt glue - #4911

Merged
borisbat merged 4 commits into
masterfrom
bbatkin/static-dot-followup
Dec 5, 2026
Merged

borisbat merged 4 commits into
masterfrom
bbatkin/static-dot-followup

Conversation

@borisbat

@borisbat borisbat commented Dec 5, 2026

Copy link
Copy Markdown
Collaborator

Behavior change: under the no_unsafe policy, 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 the unsafe.

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 answer Class.f() with no error. das-fmt put a space in type<T>?.x.

What changes.

  • Six call rewrites copy the whole flag set of the node they replace.
  • A call through a class name is an error when a function or generic of another class matches it too.
  • das-fmt glues ., ?., !. and !?. to a type expression.
  • Structure::hasOwnFunction replaces four copies of one lookup.

Observable behavior.

  • unsafe(h.value_of()) under no_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. anotherClassAnswers and its call in the static loop of InferTypes::visit(ExprInvoke*); the flag copies are one line each.

Validation, claims, ledger

Validation

  • Full test_aot lane green on the head commit 8b957a8f30 (preflight tests-aot run alone, Linux, LLVM on). With all eight lanes sharing the box the same lane had one red, tests/lint/test_parallel_equivalence.das at 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.
  • The docs lane's Sphinx step is red on the build box only for tutorial recording is not staged warnings; staging needs GitHub credentials the box does not have.
  • Red first: on the unfixed build the formatter test fails, four of the five unsafe shapes compile under the policy, and the hidden-method fixture prints the other class's answer.
  • The second and third commits each build and pass the unsafe test on their own; the fourth is the refactor.
  • Citation audit: src/ast/ARCHITECTURE_STATIC_MEMBERS.md#static-member-dot matches the code at its new citer anotherClassAnswers.
  • The per-checklist audits, the test-coverage audit and the duplicate audit of the pre-PR checklist were not rerun for this follow-up; one external review round ran on the head.

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

  • The class check is strict: a matching candidate of another same-named class is an error even where overload choice would have picked the right class's plain function.
  • A named-argument call through a class name in the same corner (a generic that cannot see the class's module) is not held to the class check.

borisbat and others added 4 commits December 4, 2026 21:42
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>
Copilot AI balanced review requested due to automatic review settings December 5, 2026 06:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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 genFlags when rewriting call/operator nodes so no_unsafe enforcement can’t be bypassed by rewrites.
  • Error on Class.method(...) when a different same-named class can also match (adds anotherClassAnswers and fixtures).
  • Glue member-access operators (., ?., !., !?.) to type expressions in das-fmt and extend formatter tests.
  • Refactor repeated structure-function lookups via Structure::hasOwnFunction and 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.

Comment thread tests/language/uncategorized_no_aot.das Resolved
@borisbat
borisbat merged commit 66e51cb into master Dec 5, 2026
68 checks passed
@borisbat
borisbat deleted the bbatkin/static-dot-followup branch December 5, 2026 08:51
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