semantifold 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/build/src/backends/effects.js +3 -1
- package/build/src/backends/php.d.ts.map +1 -1
- package/build/src/backends/php.js +56 -3
- package/build/src/backends/python.js +11 -7
- package/build/src/backends/scalars.js +2 -2
- package/build/src/backends/shared.d.ts +2 -1
- package/build/src/backends/shared.d.ts.map +1 -1
- package/build/src/backends/shared.js +210 -8
- package/build/src/backends/writer.d.ts +18 -4
- package/build/src/backends/writer.d.ts.map +1 -1
- package/build/src/backends/writer.js +40 -4
- package/build/src/frontends/java.d.ts +1 -1
- package/build/src/frontends/java.d.ts.map +1 -1
- package/build/src/frontends/java.js +14 -11
- package/build/src/frontends/javascript-typescript.d.ts +1 -1
- package/build/src/frontends/javascript-typescript.d.ts.map +1 -1
- package/build/src/frontends/javascript-typescript.js +17 -17
- package/build/src/frontends/php.d.ts +5 -1
- package/build/src/frontends/php.d.ts.map +1 -1
- package/build/src/frontends/php.js +159 -31
- package/build/src/frontends/python.d.ts.map +1 -1
- package/build/src/frontends/python.js +37 -7
- package/build/src/frontends/ruby.d.ts +1 -1
- package/build/src/frontends/ruby.d.ts.map +1 -1
- package/build/src/frontends/ruby.js +12 -9
- package/build/src/frontends/types.d.ts +9 -2
- package/build/src/frontends/types.d.ts.map +1 -1
- package/build/src/frontends/types.js +26 -9
- package/build/src/language-registry.d.ts.map +1 -1
- package/build/src/language-registry.js +30 -6
- package/build/src/mapping.d.ts.map +1 -1
- package/build/src/mapping.js +4 -2
- package/build/src/semantic/effects.d.ts.map +1 -1
- package/build/src/semantic/effects.js +3 -1
- package/build/src/semantic/provenance.d.ts.map +1 -1
- package/build/src/semantic/provenance.js +37 -4
- package/build/src/semantic/types.d.ts +140 -9
- package/build/src/semantic/types.d.ts.map +1 -1
- package/build/src/semantic/types.js +37 -6
- package/build/src/semantic/validate.d.ts +31 -2
- package/build/src/semantic/validate.d.ts.map +1 -1
- package/build/src/semantic/validate.js +347 -28
- package/docs/adr-bounded-subtyping.md +180 -0
- package/docs/goals.md +1 -1
- package/docs/language-support.md +5 -4
- package/docs/testing.md +2 -2
- package/package.json +1 -1
- package/src/backends/effects.js +1 -0
- package/src/backends/php.js +56 -2
- package/src/backends/python.js +10 -4
- package/src/backends/scalars.js +1 -1
- package/src/backends/shared.js +211 -7
- package/src/backends/writer.js +41 -3
- package/src/frontends/java.js +13 -10
- package/src/frontends/javascript-typescript.js +16 -16
- package/src/frontends/php.js +175 -31
- package/src/frontends/python.js +39 -5
- package/src/frontends/ruby.js +11 -8
- package/src/frontends/types.js +26 -8
- package/src/language-registry.js +29 -5
- package/src/mapping.js +3 -1
- package/src/semantic/effects.js +1 -0
- package/src/semantic/provenance.js +34 -3
- package/src/semantic/types.js +39 -5
- package/src/semantic/validate.js +378 -27
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# ADR: Bounded subtyping — nominal interfaces with exact implementation contracts
|
|
2
|
+
|
|
3
|
+
- Status: `accepted` (adopted for PHP in this issue's implementation; the remaining cohort languages land per the follow-up plan below)
|
|
4
|
+
- Issue: STOE-60 (Semantifold core — inheritance, interfaces and trait/mixin composition beyond closed reference classes)
|
|
5
|
+
- Depends on: Task 033 reference classes (`docs/language-support.md`, `todo/033-reference-classes-methods-and-constructors.md`) for the closed nominal class, receiver, privacy, and initialization model this ADR extends and never weakens.
|
|
6
|
+
|
|
7
|
+
## Context
|
|
8
|
+
|
|
9
|
+
Task 033 delivered closed reference classes: nominal identities, private mutable state, one exact constructor, a closed method set, and purely nominal closed dispatch. Inheritance, interfaces, traits/mixins, reopening, and virtual/dynamic dispatch are explicitly excluded, so no polymorphic domain model can be expressed: a function parameter, return, local, or collection can only name one concrete class, and there is no way to state a shared method contract across classes.
|
|
10
|
+
|
|
11
|
+
The repository's guiding principles (AGENTS.md, `todo/README.md`) constrain the design:
|
|
12
|
+
|
|
13
|
+
1. Model meaning once: the semantic IR carries types and resolution facts, never target spelling.
|
|
14
|
+
2. Fail loudly: a target that cannot honor a contract reports `UNSUPPORTED_CAPABILITY` before any partial artifact.
|
|
15
|
+
3. Prefer a precise portable profile: dispatch, override, and visibility rules require explicit contracts, not symbol substitution.
|
|
16
|
+
4. No structural substitution: a lookalike never satisfies a nominal type.
|
|
17
|
+
5. Task 033 semantics are frozen: freshness, exact-once field initialization, receiver-before-argument order, declaring-receiver privacy, and aliasing-not-copying stay exactly as delivered.
|
|
18
|
+
|
|
19
|
+
This ADR decides the shape of subtyping. Per-language source spellings, generated shapes, and acceptance corpora are separate per-language specs (see Follow-ups).
|
|
20
|
+
|
|
21
|
+
## Decision 1 — Interfaces with exact implementation contracts; no class-to-class inheritance
|
|
22
|
+
|
|
23
|
+
The admitted model is **nominal interfaces plus exact `implements` contracts**. A class may implement one or more interfaces; a class never extends another class, and there are no abstract classes, superclass constructors, inherited fields, inherited methods, or `super` calls.
|
|
24
|
+
|
|
25
|
+
Rationale:
|
|
26
|
+
|
|
27
|
+
- The polymorphism that domain models actually need — a shared method contract behind parameter/return/local/collection positions — is fully expressible with interfaces; implementation inheritance mostly buys code reuse, which the model can later supply through composition (holding records or references as private fields) without inheriting state or construction semantics.
|
|
28
|
+
- Implementation inheritance collides with Task 033's construction contract: "exactly one constructor" and "every field initialized exactly once before the reference escapes" do not survive parent-constructor chaining, inherited private fields, or partial initialization across a class hierarchy.
|
|
29
|
+
- Ruby has single class inheritance but no native interface construct, JavaScript has `extends`/`class` but no nominal interface, and PHP/Java/TypeScript have both — a class-inheritance contract would be the least common denominator and would import constructor-chaining and visibility-variance questions this model does not need.
|
|
30
|
+
- Excluding class inheritance keeps the class cohort closed and enumerable per module, which is what makes the override contract statically checkable.
|
|
31
|
+
|
|
32
|
+
`extends` in the admitted grammar means **interface-extends-interface only** (Decision 3). Every source spelling of class-to-class `extends`, `super`, abstract classes, and inherited members remains `UNSUPPORTED_SYNTAX`, exactly as today.
|
|
33
|
+
|
|
34
|
+
## Decision 2 — `InterfaceDeclaration` is a closed signature-only nominal type
|
|
35
|
+
|
|
36
|
+
The semantic IR gains:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
InterfaceDeclaration
|
|
40
|
+
kind: "InterfaceDeclaration"
|
|
41
|
+
id?: string // stable module-local identity (`interface:N`), required after validation
|
|
42
|
+
name: string // source-visible name
|
|
43
|
+
extends?: InterfaceType[] // direct interface parents in source order; omitted when empty
|
|
44
|
+
methods: InterfaceMethodDeclaration[] // ordered closed signature set
|
|
45
|
+
|
|
46
|
+
InterfaceMethodDeclaration
|
|
47
|
+
kind: "InterfaceMethodDeclaration"
|
|
48
|
+
id?: string // stable interface-scoped identity (`interface:N:method:N`), required after validation
|
|
49
|
+
name: string
|
|
50
|
+
parameters: Parameter[] // exact positional required parameters with explicit types
|
|
51
|
+
returnType: SemanticFunctionReturnType // explicit value or void return
|
|
52
|
+
|
|
53
|
+
InterfaceType
|
|
54
|
+
kind: "InterfaceType"
|
|
55
|
+
declarationId: string // exact interface declaration identity
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`ClassDeclaration` gains an optional `implements?: InterfaceType[]` member (source order; omitted when empty) and each `MethodDeclaration` gains an optional resolved `implements?: {interfaceId: string, methodId: string}` fact after validation.
|
|
59
|
+
|
|
60
|
+
Hard rules:
|
|
61
|
+
|
|
62
|
+
- Interfaces carry **no fields, no constructors, no static members, and no method bodies**. A body on an interface method (PHP/Python/Go-style default methods) is `UNSUPPORTED_SYNTAX`.
|
|
63
|
+
- Interface method signatures are explicit and complete exactly like Task 033 method signatures: named parameters, explicit types, explicit value-or-void return. No optional parameters, no defaults, no overloads, no variadics.
|
|
64
|
+
- Interface names join the existing nominal-name registry: one interface name per module, unique against classes, records, errors, functions, and other interfaces, and against the target reserved-name/collision baselines Task 033 already enforces.
|
|
65
|
+
- `InterfaceType` joins `SemanticValueType` and composes with the existing type grammar exactly like `ReferenceType`: parameters, returns, locals, list/map/ordered-map/optional constituents.
|
|
66
|
+
|
|
67
|
+
## Decision 3 — Interface composition is a closed extends DAG
|
|
68
|
+
|
|
69
|
+
An interface may extend zero or more interfaces. The transitive method set is the flattened union in deterministic declaration order (parents first, then the interface's own methods, in source order). Cycles, duplicate inherited names, and a redeclared method whose signature differs from the inherited one are located diagnostics (`INTERFACE_CYCLE`, `INTERFACE_MEMBER_DUPLICATE`). Interface-to-interface `extends` is the only admitted `extends` spelling.
|
|
70
|
+
|
|
71
|
+
## Decision 4 — The override contract is exact and total
|
|
72
|
+
|
|
73
|
+
A class with `implements [I1..In]` must supply, in its own closed method set, exactly one method matching each flattened interface signature:
|
|
74
|
+
|
|
75
|
+
- exact name, exact ordered parameter types, exact arity, exact return type (value type or void — never widened or narrowed);
|
|
76
|
+
- no interface method may be private to the class (visibility rules per Decision 7);
|
|
77
|
+
- duplicate class methods satisfying the same interface member, a missing member, a signature mismatch, and an arity mismatch are located diagnostics (`INTERFACE_MEMBER_MISSING`, `INTERFACE_MEMBER_SIGNATURE_MISMATCH`), reported before any writer allocation;
|
|
78
|
+
- a class may implement several interfaces, and one class method may satisfy several interfaces' identical signatures;
|
|
79
|
+
- interface method names follow the same target preflight rules as Task 033 method names (for example Ruby target preflight still rejects setter-style names ending in `=`).
|
|
80
|
+
|
|
81
|
+
The contract is checked at the declaration, once, statically. Nothing about it is deferred to runtime.
|
|
82
|
+
|
|
83
|
+
## Decision 5 — Dispatch is nominal at the call site; the target's native lookup selects the implementation
|
|
84
|
+
|
|
85
|
+
`MethodCallExpression` on an `InterfaceType` receiver resolves against the **interface's flattened signature set**: the resolved `ResolvedMethodSignature` records the declaring interface identity and the exact signature, exactly as Task 033 records the declaring class. Call-site validation never inspects which concrete classes exist.
|
|
86
|
+
|
|
87
|
+
At runtime the target's own native method lookup performs the selection (PHP interface dispatch, Ruby module inclusion, JavaScript prototype lookup, TypeScript compile-time erasure plus native lookup, Java virtual dispatch). This is target-native lowering, not a Semantifold dispatch model: the semantic IR carries no dispatch tables, virtual slots, method objects, vtables, or message sends, and Semantifold never resolves a method against a concrete class behind an interface receiver. Two classes implementing the same interface produce byte-identical generated call sites.
|
|
88
|
+
|
|
89
|
+
Explicitly still excluded (unchanged from Task 033): computed/dynamic method names, `send`/`apply`/`public_send`, `method_missing`, function-valued "lambdas stored in fields", reflection, and any construct that turns a method name into a runtime value.
|
|
90
|
+
|
|
91
|
+
## Decision 6 — Value flow: implicit upcast only, no casts, no type tests
|
|
92
|
+
|
|
93
|
+
- A `ReferenceConstruction` of class `C` is assignable to an `InterfaceType` `I` (and to `J`) exactly when `C implements` includes `I` (or a transitively extended `J`). This is the only admitted widening, and it is checked statically at every assignment, argument, return, and collection-element position.
|
|
94
|
+
- An interface-typed value never flows back to a class type or to a narrower interface: there are no downcasts, no `as`/`instanceof`/`is_a?`/`is`/`kind_of?`/type predicates on interface receivers, no exhaustive switch over implementations, and no runtime type queries of any kind. The existing general exclusion of casts/assertions stands.
|
|
95
|
+
- Interface-typed locals require the same explicit type carriers Task 033 requires wherever the source language does not enforce them (JSDoc `@type`, Ruby type comments, etc.).
|
|
96
|
+
- Task 033 identity semantics carry over unchanged: interface-typed bindings alias the same fresh instance; there is still no identity equality, hashing, ordering, cloning, or serialization.
|
|
97
|
+
|
|
98
|
+
## Decision 7 — Visibility and encapsulation
|
|
99
|
+
|
|
100
|
+
- Interface members are public to the module cohort by definition; the implementing class method must be public in the language profile (Java package-private follows the existing Task 033 Java profile: package-private interface, package-private implementing class methods).
|
|
101
|
+
- Private fields remain declaring-class-only through the semantic receiver. An interface receiver can never reach any field: `PrivateFieldRead`/`PrivateFieldWriteStatement` remain valid only on the declaring-class `ReceiverExpression` inside the declaring class, never on an interface-typed binding.
|
|
102
|
+
- Interfaces do not constrain a class's private state or extra methods: a class may have any Task 033-legal fields and methods beyond its interface contract.
|
|
103
|
+
|
|
104
|
+
## Decision 8 — Capability, cohort, and fail-loud boundaries
|
|
105
|
+
|
|
106
|
+
The registry gains one capability flag `boundedSubtyping`, valid only where `referenceClasses: true` (a language cannot advertise interfaces before it advertises closed reference classes). Adoption order follows the existing cohort discipline:
|
|
107
|
+
|
|
108
|
+
1. **Original five first** (PHP, Ruby, JavaScript/JSDoc, TypeScript, Java) — the Task 033 cohort, in the same single-module scope Task 033 shipped with. PHP is adopted today; Ruby, JavaScript/JSDoc, TypeScript, and Java keep `boundedSubtyping: false` until their per-language interface profiles land.
|
|
109
|
+
2. **Each Wave-2 language when it adopts `referenceClasses`** (Kotlin, Python, C#, Go, Rust, Swift, Dart, then C/C++ and Zig as their reference-class lanes land), each with its own exact native profile spec.
|
|
110
|
+
|
|
111
|
+
A language that advertises `boundedSubtyping: false` — today every language outside the original five, plus browser Wasm, Android/Flutter/iOS application roles until their lanes say otherwise — rejects any interface-bearing module transactionally with `UNSUPPORTED_CAPABILITY` before source, bytes, or a partial artifact set is exposed, exactly as non-cohort languages reject Task 033 class IR today.
|
|
112
|
+
|
|
113
|
+
## Decision 9 — Explicit permanent exclusions
|
|
114
|
+
|
|
115
|
+
Unless a future ADR admits them, all of the following stay out of the model and stay `UNSUPPORTED_SYNTAX`/`UNSUPPORTED_CAPABILITY`:
|
|
116
|
+
|
|
117
|
+
- class-to-class inheritance, abstract classes, `super`, inherited constructors/fields/methods, constructor chaining;
|
|
118
|
+
- multiple implementation inheritance, mixins/traits with state or behavior, Ruby module `prepend`/refinement, JavaScript prototype mutation, Python MRO beyond a single base;
|
|
119
|
+
- reopening, monkey-patching, duck typing, structural interface satisfaction, implicit interface conformance without an explicit `implements` declaration;
|
|
120
|
+
- default/implemented interface methods, static or constant interface members, interface generics (until Task 012 generics compose with interfaces in a separate decision), variance annotations (interfaces are invariant);
|
|
121
|
+
- downcasts, type tests, exhaustive matching over implementors, runtime type inspection, reflection;
|
|
122
|
+
- virtual/dynamic sends beyond the target's own closed native lookup for a statically resolved interface method (Decision 5);
|
|
123
|
+
- identity equality/hashing/ordering, serialization, cloning, destructors, async interface methods, concurrency.
|
|
124
|
+
|
|
125
|
+
## Per-language source profiles (exact native forms)
|
|
126
|
+
|
|
127
|
+
Frontends recognize exactly one canonical spelling per language and account for every parser child, modifier, and annotation; anything else is `UNSUPPORTED_SYNTAX`.
|
|
128
|
+
|
|
129
|
+
| Language | Interface declaration | Implementation | Interface-typed binding |
|
|
130
|
+
| --- | --- | --- | --- |
|
|
131
|
+
| PHP | `interface Name { public function m(T $p): R; }` (signature only) | `final class C implements I1, I2` | native parameter/return/local types |
|
|
132
|
+
| Ruby | `interface Name` declaration with per-method type-comment signatures (compiler-qualified spelling, mirroring the bounded RBS-style convention) | `class C` with `include Name` and matching `def` bodies | type comments, as Task 033 |
|
|
133
|
+
| JavaScript/JSDoc | `/** @interface */` class-shaped signature scaffold with complete `@param`/`@return` per method | `@implements {Name}` on the Task 033 canonical class | JSDoc `@type` carriers |
|
|
134
|
+
| TypeScript | `interface Name { m(p: T): R }` (non-exported, signature only) | `class C implements I1, I2` (Task 033 canonical class body) | native type annotations |
|
|
135
|
+
| Java | package-private `interface Name { R m(T p); }` | package-private `final class C implements I1, I2` (Task 033 canonical class) | native types, `Main.java` contract unchanged |
|
|
136
|
+
| Python (Wave 2) | `typing.Protocol`-shaped method stubs with full annotations | explicit inheritance of the protocol base in the class header | annotations |
|
|
137
|
+
| C# (Wave 2) | `interface IName { R M(T p); }` | `sealed class C : I1, I2` | native types |
|
|
138
|
+
| Go (Wave 2) | named `type I interface { M(p T) R }` method set | method-set satisfaction proven against the explicit named interface declaration only | named interface type |
|
|
139
|
+
| Rust (Wave 2) | `trait I { fn m(&self, p: T) -> R; }` with explicit `impl I for C` | `impl I for C` blocks | trait-object position decided per spec (no dynamic dispatch unless the spec pins a closed form) |
|
|
140
|
+
| Swift (Wave 2) | `protocol IName { func m(_ p: T) -> R }` | `final class C: I1, I2` | native protocol types |
|
|
141
|
+
| Kotlin (Wave 2) | `interface IName { fun m(p: T): R }` | `class C : I1, I2` | native types |
|
|
142
|
+
| Dart (Wave 2) | `abstract class IName { R m(T p); }` signature-only form | `class C implements I1, I2` | native types |
|
|
143
|
+
| C / C++ / Zig | no conformant native interface construct in the current profiles — remain excluded until a per-language spec decides a compiler-owned closed dispatch shape | — | — |
|
|
144
|
+
|
|
145
|
+
## Per-target backend representations
|
|
146
|
+
|
|
147
|
+
Backends emit the target's native interface construct and native call spelling from validated semantic nodes; they never erase an interface into a map, function table, or tagged union.
|
|
148
|
+
|
|
149
|
+
| Target | Representation |
|
|
150
|
+
| --- | --- |
|
|
151
|
+
| PHP | native `interface` + `implements`; typed signatures |
|
|
152
|
+
| Ruby | compiler-owned generated `module Name` with the contract documented and `include Name` on the class; method bodies remain the class's own |
|
|
153
|
+
| JavaScript | JSDoc `@interface`/`@implements` scaffold plus native method calls (nominal guarantee lives in the compiler, generated code stays plain ES) |
|
|
154
|
+
| TypeScript | native `interface` + `implements` |
|
|
155
|
+
| Java | package-private `interface` + `implements`; single-file `Main.java` composition rules extended to nested interfaces |
|
|
156
|
+
| Python / C# / Go / Rust / Swift / Kotlin / Dart | native protocol/interface/trait/protocol/interface/abstract-class forms per the Wave-2 specs; each spec pins the exact dispatch lowering and proves it with real toolchains |
|
|
157
|
+
| C / C++ / Zig / browser Wasm / application roles | `UNSUPPORTED_CAPABILITY` for interface-bearing IR until their lanes admit it |
|
|
158
|
+
|
|
159
|
+
Backend preflight revalidates the complete interface graph — identities, flattened method sets, override contracts, name collisions against target baselines, receiver types, and upcast legality — before writer allocation, and generated code reparses to the same interface/member identities wherever the target has a reparse lane.
|
|
160
|
+
|
|
161
|
+
## Diagnostics
|
|
162
|
+
|
|
163
|
+
New stable codes, all located and all raised before artifact exposure: `DUPLICATE_INTERFACE`, `UNKNOWN_INTERFACE`, `INTERFACE_CYCLE`, `INTERFACE_MEMBER_DUPLICATE`, `INTERFACE_MEMBER_MISSING`, `INTERFACE_MEMBER_SIGNATURE_MISMATCH`, `INTERFACE_NAME_COLLISION`, `INTERFACE_TYPE_MISMATCH` (illegal upcast/assignment), `INTERFACE_RECEIVER_INVALID` (non-interface receiver or private-field reach through an interface binding). Malformed caller-owned IR reports the existing transactional `UNSUPPORTED_CAPABILITY`/`TYPE_MISMATCH` family. Frontends locate excluded inheritance, `super`, reopened classes, default methods, implicit conformance, and type tests as `UNSUPPORTED_SYNTAX`.
|
|
164
|
+
|
|
165
|
+
## Rejected alternatives
|
|
166
|
+
|
|
167
|
+
- **Single-root class inheritance with virtual dispatch** (PHP/Java/TypeScript-shaped): rejected by Decision 1 — it reopens constructor chaining, partial initialization, inherited private state, and visibility variance, and its least-common-denominator across Ruby/JavaScript profiles is weaker than the interface contract.
|
|
168
|
+
- **Interface-only composition without interface `extends`**: rejected as unnecessarily restrictive; a closed extends DAG is statically checkable and native in every cohort language.
|
|
169
|
+
- **Structural/duck typing**: rejected outright — it violates the repository's nominal-typing principle and cannot be validated fail-loudly.
|
|
170
|
+
- **Composition-only (no subtyping; hand adapters)**: rejected as insufficient — it cannot express polymorphic parameters, which is the gap this issue names.
|
|
171
|
+
|
|
172
|
+
## Follow-ups
|
|
173
|
+
|
|
174
|
+
1. Semantic IR/validation: `InterfaceDeclaration`/`InterfaceMethodDeclaration`/`InterfaceType`, `implements` on classes, registry `boundedSubtyping` flag, shared acceptance/rejection specs (one top-level `describe` per spec file).
|
|
175
|
+
2. Original-five frontend/backend per-language specs: exact source spellings, generated shapes, reparse proofs, and real-toolchain execution (PHP, Ruby, Node, `tsc`, `javac`/`java`) including override-contract negatives.
|
|
176
|
+
3. Wave-2 per-language specs as each language's `referenceClasses` lane lands.
|
|
177
|
+
4. Docs: extend the Task 033 section of `docs/language-support.md` with the admitted interface profile once implemented.
|
|
178
|
+
5. Real-toolchain acceptance and exact-head TensorBuzz CI per the repo gates.
|
|
179
|
+
|
|
180
|
+
Recorded as roadmap task [048 — Bounded subtyping implementation](../todo/048-bounded-subtyping-implementation.md).
|
package/docs/goals.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Semantifold's long-term goal is a language-neutral toolkit for understanding, transforming, generating, and eventually executing programs through a shared high-level semantic representation. The representation should make types, control flow, calls, declarations, diagnostics, and source provenance understandable without exposing a language parser's private tree.
|
|
4
4
|
|
|
5
|
-
The current source tree proves one minimal Tasks 001–004 vertical slice across fifteen registered source languages: PHP, Ruby, JavaScript, TypeScript, Java, Kotlin/JVM, strictly annotated Python, canonical C#, bounded Go, C17, C++20, Rust edition 2021, Swift, Dart, and Zig. Dart and
|
|
5
|
+
The current source tree proves one minimal Tasks 001–004 vertical slice across fifteen registered source languages: PHP, Ruby, JavaScript, TypeScript, Java, Kotlin/JVM, strictly annotated Python, canonical C#, bounded Go, C17, C++20, Rust edition 2021, Swift, Dart, and Zig. C, Dart, Zig, and Python additionally implement the bounded Task 005 required-function/call profile; the original five retain the delivered Task 013 acceptance gate for the combined Tasks 001–008 profile, Task 009 nominal closed records, Task 010 explicit acyclic multi-source semantic programs, Task 011 exact nominal typed unchecked errors, and Task 012 invariant unbounded function/record type parameters with closed applications and argument-only first-order call inference. Task 014 is delivered through PR #41, Task 032 through PR #42, Task 033 through PR #43, and Task 034 through PR #44. Task 035 is delivered through PR #45 and merge commit `a2aad9d4932bfc6087adc4ff8bca43678c92413c`, with versioned canonical standard-library contracts, target host providers and protected native bindings, capability negotiation, and program-mode provider linking. Task 036 is delivered through PR #46 and merge `9aba48f9d48bcef4fd4c9275aec14bfcc4f0904c`; it adds bounded versioned executable qualification facades and exact parser-backed native identity resolution for the original five. Task 037 adds only the first concrete Ruby-source-to-PHP-target blocking TCP/line-output slice on those foundations. The source tree includes versioned source provenance, deterministic semantic node/symbol identity, range-based generated mappings, Source Map v3 interop, composition, and diagnostic remapping across those bounded profiles. The published `semantifold@0.6.0` and annotated `v0.6.0` target exact commit `f76e6d64b388d65959e77f747ae2d60a999d61f5`, including Task 028 from PR #51 and Task 031 from PR #52. Neither the source tree nor that release provides a general analyzer, transformation API, interpreter, optimizer, implicit project/package discovery, debugger integration, coverage remapping, or lossless formatter.
|
|
6
6
|
|
|
7
7
|
The long-term product direction includes bounded standard-library portability through [language compatibility stdlib/facades, canonical Semantifold stdlib contracts/capabilities, and target host providers/native bindings](standard-library-portability.md). That direction is incremental and versioned; it does not promise arbitrary standard-library coverage or arbitrary-application translation. The `0.3.0` release has no imports, classes or methods, loops, optional values, typed errors, resources, host APIs, or stdlib portability.
|
|
8
8
|
|
package/docs/language-support.md
CHANGED
|
@@ -12,7 +12,7 @@ The immutable registry is authoritative for both dispatch and discovery:
|
|
|
12
12
|
| `typescript` | yes | yes | no | no | no | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | single | yes | rich + v3 | parse, generate, compile, execute (`tsc`, `node`) |
|
|
13
13
|
| `java` | yes | yes | no | no | no | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | single | yes | rich + v3 | parse, generate, compile, execute (`javac`, `java`) |
|
|
14
14
|
| `kotlin` | yes | yes | no | no | no | no | no | no | no | no | no | no | no | no | no | no | single | yes | rich + v3 | parse, generate, compile, execute (`kotlinc`, `java25`) |
|
|
15
|
-
| `python` | yes | yes | no | no | no |
|
|
15
|
+
| `python` | yes | yes | no | no | no | yes | no | no | no | no | no | no | no | no | no | no | single | yes | rich + v3 | parse, generate, compile, execute (`python3`) |
|
|
16
16
|
| `csharp` | yes | yes | no | no | no | no | no | no | no | no | no | no | no | no | no | no | multiple | yes | rich + v3 | parse, generate, restore, compile, execute (`dotnet`) |
|
|
17
17
|
| `go` | yes | yes | no | no | no | no | no | no | no | no | no | no | no | no | no | no | multiple | yes | rich + v3 | parse, generate, compile, validate, execute (`go`) |
|
|
18
18
|
| `cpp` | yes | yes | no | no | no | no | no | no | no | no | no | no | no | no | no | no | single | yes | rich + v3 | parse, generate, compile, link, execute (`clangpp`, native executable) |
|
|
@@ -84,7 +84,7 @@ The shared negative corpus covers parser recovery, missing types, truthiness, mi
|
|
|
84
84
|
|
|
85
85
|
## Task 005 general functions and calls
|
|
86
86
|
|
|
87
|
-
PHP, Ruby, JavaScript with JSDoc, TypeScript, Java, C, Dart, and
|
|
87
|
+
PHP, Ruby, JavaScript with JSDoc, TypeScript, Java, C, Dart, Zig, and Python accept any number of required positional parameters, including zero. The module resolver collects every unique function signature before validating bodies, assigns declarations deterministic `function:N` identities, and binds each direct call to that identity plus its ordered parameter and return types. This permits forward calls, nested calls, direct recursion, and unambiguous mutual recursion without overload or dynamic dispatch. Arity and every positional scalar type must match exactly.
|
|
88
88
|
|
|
89
89
|
Function returns are `integer`, `boolean`, `string`, or `void`. A non-void function has an expression on every reachable return and returns on every reachable path. A void function may fall through or use a bare return, and its call is legal only as an `ExpressionStatement`. Void is never a value: it cannot type a parameter or local, initialize or assign a binding, become an argument or operand, be printed, or be returned as a value. Generation revalidates declaration identities and complete resolved signatures in externally supplied IR. Function names, parameters, return annotations, callees, arguments, and resolution references retain deterministic parser-backed provenance and mappings.
|
|
90
90
|
|
|
@@ -97,8 +97,9 @@ The source profiles remain deliberately exact:
|
|
|
97
97
|
- C accepts file-scope `static` semantic functions with any number of explicitly typed named parameters — spelled `void` for an empty list — exact scalar or `void` returns, and unqualified direct calls. A `static` prototype may precede a definition for forward or mutual recursion and must agree exactly with its unique definition; a prototype without a definition, a conflicting prototype, an implicit declaration, a bare return in a non-void function, or `void` used as a parameter, local, argument, operand or printed value is rejected. Generated zero-parameter signatures spell `(void)` and generated prototypes make forward calls and recursion compilable under `-Wstrict-prototypes`/`-Wmissing-prototypes`. See [C source and target](c.md).
|
|
98
98
|
- Dart accepts synchronous top-level functions with exact explicit `int`, `bool`, `String`, or `void` returns, explicitly typed required positional parameters, initialized typed locals, direct calls, and exact `void main()`/`print`. Inference, `var`, inferred `final`, optional/named/default arguments, methods/classes, generics, imports, dynamic/nullability, collections, exceptions, async, and isolates are rejected. Generated Dart alone may contain formatter-added trailing commas and the complete canonical private runtime prefix; neither grants those forms to ordinary source. See [Dart source and target](dart.md).
|
|
99
99
|
- Zig accepts top-level functions with exact explicit `i64`, `bool`, `[]const u8`, or `void` returns, explicitly typed required positional parameters, initialized typed `const`/`var` locals, direct calls, and the exact generated support/`pub fn main()` shell. Inference, optional/default/rest parameters, methods, containers, user slices/pointers/allocators, imports beyond the canonical standard-library support, error unions, `comptime`, generics, reflection, FFI, async, and concurrency are rejected. See [Zig source and target](zig.md).
|
|
100
|
+
- Python accepts synchronous top-level `def` functions with any number of explicitly `int`/`bool`/`str`-annotated required positional parameters and an exact `int`/`bool`/`str` or `None` return annotation, where `None` is the only void spelling. A void function may fall through or use a bare `return`, and its call is legal only as a top-level or block statement expression. Direct calls are identifier callees with positional arguments only; forward calls, direct recursion, and unambiguous mutual recursion resolve exactly. Default, positional-only, keyword-only, variadic, starred, or unannotated parameters, keyword or starred call arguments, nested function declarations, and every dynamic callee form remain rejected; a value `return` inside a `-> None` function fails with `VOID_RETURN_VALUE`.
|
|
100
101
|
|
|
101
|
-
|
|
102
|
+
C#, C++, Rust, Swift, Kotlin/JVM, Go, and browser Wasm remain on their Task 025 Tasks 001–004 profile. Their registry feature flag is false, their existing exact-two/scalar-return behavior is unchanged, and a Task-005-only arity, void return, or void call statement is a located `UNSUPPORTED_CAPABILITY` before source, bytes, or a partial artifact set is exposed. This boundary does not broaden the future Task 013 aggregate acceptance.
|
|
102
103
|
|
|
103
104
|
## Task 006 immutable lists and maps
|
|
104
105
|
|
|
@@ -170,7 +171,7 @@ Construction arguments evaluate left to right and all fields must be initialized
|
|
|
170
171
|
|
|
171
172
|
The source profiles are intentionally exact. TypeScript uses non-exported classes with explicit `private` fields, one unmodified constructor, and ordinary typed instance methods. JavaScript uses native `#private` fields with adjacent complete JSDoc on fields, constructor parameters, method parameters/returns, and reference-typed bindings. PHP uses `final class`, explicit private typed properties, one public `__construct`, and public typed instance methods. Ruby uses a closed class body with one documented `initialize`; its ordered required parameters initialize the correspondingly named instance variables, and every ordinary method has complete adjacent type comments. Ruby target preflight rejects setter-style method names ending in `=` because native setter invocation returns the assigned argument independently of the method body. Java uses a package-private `final class` with explicit private mutable fields, one package-private constructor, package-private ordinary typed methods, and a separate canonical public `Main`; when a reference method calls a semantic function, generated package-visible static `Main` methods and explicit `Main.method(...)` calls preserve access and evaluation order. All five generated forms reparse to the same semantic class/member identities and execute through the real registered toolchains.
|
|
172
173
|
|
|
173
|
-
Inheritance, interfaces, traits/mixins, class reopening or monkey-patching, prototypes, decorators/annotations, static/singleton members, computed or dynamic sends, overloads, virtual/duck dispatch, arbitrary host construction, reflection and host lifecycle/protocol hooks, public mutable fields, private access from outside the declaring receiver, identity equality/hashing/ordering, cloning, serialization, finalizers, generic or async methods/classes, and concurrency remain excluded. Constructors and methods may catch Task 011 errors internally but cannot expose an unchecked-error effect through a receiver call; that cross-feature effect contract is not invented by Task 033. Kotlin, Python, C#, Go, C, C++, Rust, Swift, and browser Wasm advertise `referenceClasses: false` and reject class-bearing modules transactionally. Task 033 is single-module: `parseProgram` and `generateProgramArtifactSet` reject class-bearing Task 010 modules before resolution or artifact allocation. It adds no Task 034 resource/effect model and no standard-library contract, facade, provider, or pairwise rewrite.
|
|
174
|
+
Inheritance, interfaces, traits/mixins, class reopening or monkey-patching, prototypes, decorators/annotations, static/singleton members, computed or dynamic sends, overloads, virtual/duck dispatch, arbitrary host construction, reflection and host lifecycle/protocol hooks, public mutable fields, private access from outside the declaring receiver, identity equality/hashing/ordering, cloning, serialization, finalizers, generic or async methods/classes, and concurrency remain excluded. The bounded subtyping model that extends this cohort — nominal interfaces with exact `implements` override contracts and no class-to-class inheritance — is decided in the [bounded subtyping ADR](adr-bounded-subtyping.md). It is adopted for PHP only today (`boundedSubtyping: true`); Ruby, JavaScript, TypeScript, and Java keep `boundedSubtyping: false` until their per-language interface profiles land, and every other target rejects interface-bearing modules transactionally. Nothing in that ADR changes the Task 033 semantics documented above. Constructors and methods may catch Task 011 errors internally but cannot expose an unchecked-error effect through a receiver call; that cross-feature effect contract is not invented by Task 033. Kotlin, Python, C#, Go, C, C++, Rust, Swift, and browser Wasm advertise `referenceClasses: false` and reject class-bearing modules transactionally. Task 033 is single-module: `parseProgram` and `generateProgramArtifactSet` reject class-bearing Task 010 modules before resolution or artifact allocation. It adds no Task 034 resource/effect model and no standard-library contract, facade, provider, or pairwise rewrite.
|
|
174
175
|
|
|
175
176
|
## Task 034 effectful capabilities and owned resource lifetime
|
|
176
177
|
|
package/docs/testing.md
CHANGED
|
@@ -36,7 +36,7 @@ These tests generate and publish source artifacts only. They do not run `javac`,
|
|
|
36
36
|
|
|
37
37
|
## Task 005 general function signatures and calls
|
|
38
38
|
|
|
39
|
-
Task 005 stays bounded to PHP, Ruby, JavaScript with JSDoc, TypeScript, Java, Dart, Zig, and
|
|
39
|
+
Task 005 stays bounded to PHP, Ruby, JavaScript with JSDoc, TypeScript, Java, Dart, Zig, C, and Python. `general-function-signatures-and-calls.spec.js` proves equivalent zero-, one-, and three-parameter signatures, complete signature collection, nested calls, terminating recursion, scalar/void returns, and the stable semantic failures across the six source fixtures, including `fixtures/functions/program.py`. `general-function-frontend-validation.spec.js` owns the excluded parameter, call, method, receiver, dispatch, annotation, overload, generic, and higher-order source forms. `general-function-backend-validation.spec.js` proves generation/reparse, exact external-IR signature revalidation, target conflicts, the public feature flag, and transactional rejection from every deferred Task 025/Wasm target. `general-function-provenance-and-mapping.spec.js` proves deterministic declaration/resolution identities and exact signature/call mappings. `general-function-runtime-execution.spec.js` invokes real PHP, Ruby, Node, local `tsc` followed by Node, `javac`, `java`, and `python3`, requiring exact `ready\n6\n` output; a missing command fails. `c-task005-acceptance.spec.js` proves the C cohort extension: generated-C reparse with identical meaning, the C fixture through every original-five text target, and real Clang execution of each original-five Task-005 fixture and the C fixture at `-O0`/`-O2` with and without sanitizers, including prototype-mediated mutual recursion and bare void returns.
|
|
40
40
|
|
|
41
41
|
Run the Task 005 files individually and sequentially:
|
|
42
42
|
|
|
@@ -49,7 +49,7 @@ npx velocious-test spec/general-function-runtime-execution.spec.js
|
|
|
49
49
|
npx velocious-test spec/c-task005-acceptance.spec.js
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
Task 013 is the separate terminal original-five aggregate gate. Task 005 does not expand that matrix or adopt
|
|
52
|
+
Task 013 is the separate terminal original-five aggregate gate. Task 013 is the separate terminal original-five aggregate gate. Task 005 does not expand that matrix or adopt C#, C++, Rust, Swift, Kotlin/JVM, Go, or browser Wasm beyond focused capability rejection.
|
|
53
53
|
|
|
54
54
|
## Task 011 typed errors and handling
|
|
55
55
|
|
package/package.json
CHANGED
package/src/backends/effects.js
CHANGED
|
@@ -266,6 +266,7 @@ function semanticTypeForIdentity(identity) {
|
|
|
266
266
|
if (identity.kind == "RecordType") return {arguments: identity.arguments?.map(semanticTypeForValueIdentity),
|
|
267
267
|
declarationId: identity.declarationId, kind: "RecordType"}
|
|
268
268
|
if (identity.kind == "ReferenceType") return {declarationId: identity.declarationId, kind: "ReferenceType"}
|
|
269
|
+
if (identity.kind == "InterfaceType") return {declarationId: identity.declarationId, kind: "InterfaceType"}
|
|
269
270
|
if (identity.kind == "OwnedResourceType") return {kind: "OwnedResourceType", resourceId: identity.resourceId}
|
|
270
271
|
if (identity.kind == "OwnedReferenceType") return {declarationId: identity.declarationId, kind: "OwnedReferenceType"}
|
|
271
272
|
return {kind: "TypeVariableReference", location: /** @type {never} */ (undefined), parameterId: identity.parameterId}
|
package/src/backends/php.js
CHANGED
|
@@ -15,6 +15,7 @@ export function generatePhp(module, writer) {
|
|
|
15
15
|
emitEffectSupport(writer, module, "php")
|
|
16
16
|
const records = module.records ?? []
|
|
17
17
|
const classes = module.classes ?? []
|
|
18
|
+
const interfaces = module.interfaces ?? []
|
|
18
19
|
const errors = module.errors ?? []
|
|
19
20
|
|
|
20
21
|
errors.forEach((error, index) => {
|
|
@@ -72,6 +73,12 @@ export function generatePhp(module, writer) {
|
|
|
72
73
|
})
|
|
73
74
|
if (records.length > 0) writer.synthetic("\n\n", "record/function separator", [module])
|
|
74
75
|
|
|
76
|
+
interfaces.forEach((declaration, interfaceIndex) => {
|
|
77
|
+
if (interfaceIndex > 0) writer.synthetic("\n\n", "interface separator", [declaration], [`/interfaces/${interfaceIndex}`])
|
|
78
|
+
emitInterface(writer, declaration, interfaceIndex)
|
|
79
|
+
})
|
|
80
|
+
if (interfaces.length > 0) writer.synthetic("\n\n", "interface/class separator", [module])
|
|
81
|
+
|
|
75
82
|
classes.forEach((declaration, classIndex) => {
|
|
76
83
|
if (classIndex > 0) writer.synthetic("\n\n", "reference class separator", [declaration], [`/classes/${classIndex}`])
|
|
77
84
|
emitReferenceClass(writer, declaration, classIndex)
|
|
@@ -156,6 +163,15 @@ function emitReferenceClass(writer, declaration, classIndex) {
|
|
|
156
163
|
writer.mapped("final class", {mappingKind: "anchor", node: declaration, path})
|
|
157
164
|
writer.synthetic(" ", "reference class spacing", [declaration], [path])
|
|
158
165
|
writer.mapped(declaration.name, {mappingKind: "exact", node: declaration, path, role: "name"})
|
|
166
|
+
const implemented = declaration.implements ?? []
|
|
167
|
+
|
|
168
|
+
if (implemented.length > 0) {
|
|
169
|
+
writer.mapped(" implements ", {mappingKind: "anchor", node: declaration, path})
|
|
170
|
+
implemented.forEach((reference, referenceIndex) => {
|
|
171
|
+
if (referenceIndex > 0) writer.mapped(", ", {mappingKind: "anchor", node: declaration, path})
|
|
172
|
+
emitType(writer, reference, `${path}/implements/${referenceIndex}`, "php")
|
|
173
|
+
})
|
|
174
|
+
}
|
|
159
175
|
writer.synthetic(" {\n", "reference class open", [declaration], [path])
|
|
160
176
|
declaration.fields.forEach((field, index) => {
|
|
161
177
|
const fieldPath = `${path}/fields/${index}`
|
|
@@ -191,6 +207,44 @@ function emitReferenceClass(writer, declaration, classIndex) {
|
|
|
191
207
|
writer.mapped("}", {mappingKind: "anchor", node: declaration, path})
|
|
192
208
|
}
|
|
193
209
|
|
|
210
|
+
/**
|
|
211
|
+
* Emits one PHP native interface declaration with signature-only members.
|
|
212
|
+
* @param {import("./writer.js").SourceWriter} writer - Source-aware writer.
|
|
213
|
+
* @param {import("../semantic/types.js").InterfaceDeclaration} declaration - Semantic interface.
|
|
214
|
+
* @param {number} interfaceIndex - Declaration index.
|
|
215
|
+
* @returns {void}
|
|
216
|
+
*/
|
|
217
|
+
function emitInterface(writer, declaration, interfaceIndex) {
|
|
218
|
+
const path = `/interfaces/${interfaceIndex}`
|
|
219
|
+
|
|
220
|
+
writer.mapped("interface", {mappingKind: "anchor", node: declaration, path})
|
|
221
|
+
writer.synthetic(" ", "interface spacing", [declaration], [path])
|
|
222
|
+
writer.mapped(declaration.name, {mappingKind: "exact", node: declaration, path, role: "name"})
|
|
223
|
+
const parents = declaration.extends ?? []
|
|
224
|
+
|
|
225
|
+
if (parents.length > 0) {
|
|
226
|
+
writer.mapped(" extends ", {mappingKind: "anchor", node: declaration, path})
|
|
227
|
+
parents.forEach((parent, parentIndex) => {
|
|
228
|
+
if (parentIndex > 0) writer.mapped(", ", {mappingKind: "anchor", node: declaration, path})
|
|
229
|
+
emitType(writer, parent, `${path}/extends/${parentIndex}`, "php")
|
|
230
|
+
})
|
|
231
|
+
}
|
|
232
|
+
writer.synthetic(" {\n", "interface open", [declaration], [path])
|
|
233
|
+
declaration.methods.forEach((method, methodIndex) => {
|
|
234
|
+
const methodPath = `${path}/methods/${methodIndex}`
|
|
235
|
+
|
|
236
|
+
if (methodIndex > 0) writer.synthetic("\n", "line break", [method], [methodPath])
|
|
237
|
+
writer.synthetic(" public function ", "interface method scaffolding", [method], [methodPath])
|
|
238
|
+
writer.mapped(method.name, {mappingKind: "exact", node: method, path: methodPath, role: "name"})
|
|
239
|
+
emitPhpParameters(writer, method.parameters, `${methodPath}/parameters`)
|
|
240
|
+
writer.synthetic(": ", "interface method return separator", [method], [methodPath])
|
|
241
|
+
emitNativePhpType(writer, method.returnType, `${methodPath}/returnType`)
|
|
242
|
+
writer.mapped(";", {mappingKind: "anchor", node: method, path: methodPath})
|
|
243
|
+
})
|
|
244
|
+
writer.synthetic("\n", "line break", [declaration], [path])
|
|
245
|
+
writer.mapped("}", {mappingKind: "anchor", node: declaration, path})
|
|
246
|
+
}
|
|
247
|
+
|
|
194
248
|
/**
|
|
195
249
|
* Emits one PHP parameter list.
|
|
196
250
|
* @param {import("./writer.js").SourceWriter} writer - Source-aware writer.
|
|
@@ -355,7 +409,7 @@ function emitNativePhpType(writer, type, path) {
|
|
|
355
409
|
})
|
|
356
410
|
return
|
|
357
411
|
}
|
|
358
|
-
if (type.kind == "ReferenceType" || type.kind == "OwnedResourceType" || type.kind == "OwnedReferenceType") {
|
|
412
|
+
if (type.kind == "ReferenceType" || type.kind == "InterfaceType" || type.kind == "OwnedResourceType" || type.kind == "OwnedReferenceType") {
|
|
359
413
|
emitType(writer, type, path, "php")
|
|
360
414
|
return
|
|
361
415
|
}
|
|
@@ -365,7 +419,7 @@ function emitNativePhpType(writer, type, path) {
|
|
|
365
419
|
}
|
|
366
420
|
if (type.kind == "OptionalType") {
|
|
367
421
|
writer.mapped("?", {mappingKind: "exact", node: type, path, role: "type"})
|
|
368
|
-
if (type.valueType.kind == "RecordType") emitNativePhpType(writer, type.valueType, `${path}/valueType`)
|
|
422
|
+
if (type.valueType.kind == "RecordType" || type.valueType.kind == "InterfaceType") emitNativePhpType(writer, type.valueType, `${path}/valueType`)
|
|
369
423
|
else if (type.valueType.kind == "TypeReference") emitType(writer, type.valueType, `${path}/valueType`, "php")
|
|
370
424
|
else writer.mapped("array", {mappingKind: "anchor", node: type, path})
|
|
371
425
|
return
|
package/src/backends/python.js
CHANGED
|
@@ -81,14 +81,20 @@ function emitStatement(writer, statement, indent, path) {
|
|
|
81
81
|
emitIf(writer, statement, indent, path, "if")
|
|
82
82
|
return
|
|
83
83
|
}
|
|
84
|
-
if (statement.kind == "ExpressionStatement")
|
|
84
|
+
if (statement.kind == "ExpressionStatement") {
|
|
85
|
+
writer.synthetic(indent, "indentation", [statement], [path])
|
|
86
|
+
emitExpression(writer, statement.expression, `${path}/expression`, "python", identity)
|
|
87
|
+
writer.synthetic("\n", "line break", [statement], [path])
|
|
88
|
+
return
|
|
89
|
+
}
|
|
85
90
|
|
|
86
91
|
writer.synthetic(indent, "indentation", [statement], [path])
|
|
87
92
|
if (statement.kind == "ReturnStatement") {
|
|
88
|
-
if (!statement.expression) throw new TypeError("Python bare return reached emission.")
|
|
89
93
|
writer.mapped("return", {mappingKind: "anchor", node: statement, path})
|
|
90
|
-
|
|
91
|
-
|
|
94
|
+
if (statement.expression) {
|
|
95
|
+
writer.synthetic(" ", "return spacing", [statement], [path])
|
|
96
|
+
emitExpression(writer, statement.expression, `${path}/expression`, "python", identity)
|
|
97
|
+
}
|
|
92
98
|
writer.synthetic("\n", "line break", [statement], [path])
|
|
93
99
|
return
|
|
94
100
|
}
|
package/src/backends/scalars.js
CHANGED
|
@@ -37,7 +37,7 @@ export function emitScalarType(language, type) {
|
|
|
37
37
|
* @returns {string} Exact target spelling.
|
|
38
38
|
*/
|
|
39
39
|
export function emitSemanticType(language, type, javaBoxed = false) {
|
|
40
|
-
if (type.kind == "RecordType" || type.kind == "ReferenceType") {
|
|
40
|
+
if (type.kind == "RecordType" || type.kind == "ReferenceType" || type.kind == "InterfaceType") {
|
|
41
41
|
throw new TypeError("Nominal type emission requires declaration context.")
|
|
42
42
|
}
|
|
43
43
|
if (type.kind == "OwnedResourceType" || type.kind == "OwnedReferenceType") {
|