Commit 9982420
class_super: synth derived ctor chains super + suppress 0-arg when user has ctor
Follow-up to #2892. Closes the synth-ctor side of the silent-bypass family.
PR1 made super(...) mandatory on every CFG path of a user-defined derived
ctor and hard-rejected super.X() skipping a user-coded intermediate. But it
left two gaps: (a) a fully empty class Derived : Base {} still got the
pre-existing 0-arg field-init synth ctor that never called Base's ctor, so
new Derived() silently bypassed Base's invariants; (b) a class with an
args-only user ctor (def Foo(int)) also got a pre-existing 0-arg synth that
silently bypassed the user ctor on new Foo(). Both close here.
S2 Synth-chain ctor for implicit-default-derived classes
- InferTypes::visit(Structure*) now fires tryMakeStructureCtor when any
ancestor has a user ctor (not just on field-init), so empty intermediates
get a chain ctor that lets further-derived classes reach the deepest
user code in one call.
- makeConstructor emits a let-self / call ChainTarget-ChainTarget(self) /
return self body when findChainCtorAncestor() returns non-null. The
walk-past skips empty intermediates so the call lands on the closest
user-ctored ancestor; that's required because intermediate synth ctors
only register the factory (no (self : Mid) method form to walk to).
S2d Hard-error when no default ancestor ctor exists
- If a synth-needed class's closest user-ctored ancestor has no 0-arg
signature (or all-defaulted args), error 30322 (missing_super_call)
fires with a fix-it pointing at the offending ancestor by name. New
tests/language/failed_parent_no_default* cover the direct and skip-empty
walks.
Option-A 0-arg synth suppression (the part Boris asked for)
- tryMakeStructureCtor skips emission entirely when var->isClass and the
class has any user ctor. Pre-PR2 daslang auto-synthesized a 0-arg field-
init ctor whenever no 0-arg user ctor existed, which let new Class()
silently bypass an args-only user ctor's invariants. Matches C++/Java/C#
convention: providing any ctor opts out of the compiler-generated
default. Structs keep the old behavior (no inheritance, no super to
bypass). One in-tree fixture (cant_access_private_members.das) used the
silent-bypass form and is updated to pass the required arg.
Lint walks ancestors
- PR1's lint only triggered when fn->classParent->parent had a user ctor.
With chain synth in place, an empty intermediate would propagate the
requirement: C : B : A where B is empty and A has user ctor must lint
C's user ctor for missing super(). lint now uses findChainCtorAncestor.
Suggestion text and countSuperCalls target both update to the resolved
ancestor name (matches what super(...) actually resolves to via the
walk-up in ast_infer_type.cpp:5682).
Helper: findChainCtorAncestor (ast_generate.{h,cpp})
- Shared by lint, gate, and makeConstructor - single source of truth for
"closest ancestor with a user ctor, skipping empty intermediates."
Replaces three open-coded for-loops and the unused
parentHasUserCtor() shim.
Helper methods on Structure
- Structure::hasUserConstructor() - any non-generated Klass-Klass exists
- Structure::hasUserDefaultConstructor() - 0-arg-callable user ctor exists
- Both look up by name hash via the class's own module (ctors are always
co-located with their class), with a classParent == this identity check
that defends against same-named classes in other modules (the in-tree
corpus already has multiple ContextStateAgent classes).
Tests
- tests/language/super.das: ImplicitChain, two-level MidImplicit/Leaf-
Implicit (regression for the chain-through-synth-intermediate case
where the previous straight-Parent-Parent(self) approach failed
because the synth intermediate has no method form), and
DerivedWithDefault (chain resolves to parent ctor with default arg).
- tests/language/failed_parent_no_default.das: B : A where A has only
def A(int), expect 30322 + 30318/30341 cascade.
- tests/language/failed_parent_no_default_skip_empty.das: C : B : A
where B is empty, A has only def A(int). Error 30322 fires for both
B and C, naming A as the offending ancestor in each.
- tests/language/failed_super_skip_via_empty_intermediate.das: lint must
flag C's missing super even though immediate parent B is empty.
Docs
- doc/source/reference/language/classes.rst: implicit-chain section
+ Option-A suppression note.
- doc/source/reference/tutorials/18_classes.rst + tutorials/language/
18_classes.das: implicit-chain example with class Pet : Animal {},
plus the suppression rule and the parent-no-default error case.
AOT impact
- Per plan S8: AOT hash for every class that gets a new synth chain
ctor changes. Expect AOT hash desync on first CI; AOT cache rebuilds
on next test_aot build.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent c0ce6ad commit 9982420
16 files changed
Lines changed: 390 additions & 47 deletions
File tree
- doc/source/reference
- language
- tutorials
- include/daScript/ast
- src/ast
- tests/language
- tutorials/language
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
184 | 200 | | |
185 | 201 | | |
186 | 202 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
78 | 119 | | |
79 | 120 | | |
80 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
288 | 288 | | |
289 | 289 | | |
290 | 290 | | |
| 291 | + | |
| 292 | + | |
291 | 293 | | |
292 | 294 | | |
293 | 295 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
86 | 94 | | |
87 | 95 | | |
88 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
323 | 324 | | |
324 | 325 | | |
325 | 326 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
294 | 345 | | |
295 | 346 | | |
296 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
296 | 305 | | |
297 | 306 | | |
298 | 307 | | |
| |||
308 | 317 | | |
309 | 318 | | |
310 | 319 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
319 | 368 | | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
320 | 374 | | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | 375 | | |
327 | 376 | | |
328 | 377 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
401 | 401 | | |
402 | 402 | | |
403 | 403 | | |
404 | | - | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
405 | 420 | | |
406 | 421 | | |
407 | 422 | | |
408 | | - | |
| 423 | + | |
409 | 424 | | |
410 | 425 | | |
411 | 426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
735 | 735 | | |
736 | 736 | | |
737 | 737 | | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
738 | 747 | | |
739 | 748 | | |
740 | 749 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | 320 | | |
345 | 321 | | |
346 | 322 | | |
| |||
1060 | 1036 | | |
1061 | 1037 | | |
1062 | 1038 | | |
1063 | | - | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
1064 | 1042 | | |
1065 | 1043 | | |
1066 | 1044 | | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1071 | 1049 | | |
1072 | 1050 | | |
1073 | | - | |
| 1051 | + | |
1074 | 1052 | | |
1075 | 1053 | | |
1076 | 1054 | | |
| |||
0 commit comments