kopscript 0.7.1 → 0.7.2
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/LLM.md +35 -0
- package/package.json +1 -1
package/LLM.md
CHANGED
|
@@ -504,6 +504,41 @@ signature, use different names, not overloading. (Nested function/class/interfac
|
|
|
504
504
|
declarations, by contrast, *are* a clean compile error: "Nested ... declarations are not
|
|
505
505
|
supported".)
|
|
506
506
|
|
|
507
|
+
## Common mistakes (seeded from real generation failures)
|
|
508
|
+
|
|
509
|
+
Real, observed cases where a plausible-looking guess was wrong — not hypothetical gotchas:
|
|
510
|
+
|
|
511
|
+
- **No implicit `this`.** Every reference to a member of the enclosing class — a field, a
|
|
512
|
+
property, a method call — must be `this.X`, always, everywhere, including inside a lambda.
|
|
513
|
+
`Increment()` inside a method body does **not** resolve to `this.Increment()` the way it
|
|
514
|
+
would in Java/C#/Python; it's an undefined-identifier error unless `Increment` is a real
|
|
515
|
+
free function. (Discovered building the template compiler above — templates need a
|
|
516
|
+
dedicated rewriter, `qualifyThis`, specifically because this isn't automatic.)
|
|
517
|
+
- **No `let`/`var`, ever.** Every local is `Type name = value;` — writing `let x = 5;` or a
|
|
518
|
+
bare `const x = 5;` (missing the type) is a parse error, not a lenient inferred form.
|
|
519
|
+
- **No generic functions.** `T Identity<T>(T x) { return x; }` doesn't parse — only classes
|
|
520
|
+
and interfaces take `<T>`. Don't reach for this even though every mainstream generic
|
|
521
|
+
language supports it.
|
|
522
|
+
- **Early-return doesn't narrow a nullable type.** `if (x == null) { return; } print(x.Length);`
|
|
523
|
+
still errors on `x.Length` — narrowing is scope-based (an `if`/`else` block), not
|
|
524
|
+
control-flow/reachability-based. Wrap the rest of the logic in the `if (x != null) { ... }`
|
|
525
|
+
block instead of guard-clause-and-continue.
|
|
526
|
+
- **Never write `async` on an `extern` signature.** `async task<string> text();` inside an
|
|
527
|
+
`extern class` is a parse error — declare the return type as `task<string> text();`
|
|
528
|
+
directly; `async` only means something for a body the checker validates, and an `extern`
|
|
529
|
+
signature has no body.
|
|
530
|
+
- **No object-literal syntax, anywhere, ever.** Reaching for `{ method: "POST", body: x }` to
|
|
531
|
+
call a JS API that expects one (a `fetch`-style options argument) doesn't compile — there's
|
|
532
|
+
no way to construct that value in KopScript at all. See the `extern`/`raw string` sections
|
|
533
|
+
above and Kopular's `http_runtime.js` for the actual workaround (a small hand-written JS
|
|
534
|
+
shim), not a language feature to reach for.
|
|
535
|
+
- **No ternary expression.** `cond ? a : b` doesn't parse. Use `match` on a `bool`, or an
|
|
536
|
+
`if`/`else` assigning to a local declared above it.
|
|
537
|
+
- **Two methods with the same name in one class don't error** — the second silently replaces
|
|
538
|
+
the first (see "Sharp edge" above). If a generated program seems to call the wrong
|
|
539
|
+
implementation of something, check for an accidental duplicate name before assuming a
|
|
540
|
+
compiler bug.
|
|
541
|
+
|
|
507
542
|
## Diagnostics
|
|
508
543
|
|
|
509
544
|
Every compiler error/warning is `{ severity, message, line, col }` (1-based). CLI output
|
package/package.json
CHANGED