feat(lang): a name is defined once, a local once per block, and a result is always returned
L1. Two vars, consts, enums, properties or events of one name in a program are an error naming both places (functions already were); the first used to win silently. A let / var of a name its own block already declared is an error (it used to shadow). A function with a result type whose body can reach its end without a return is an error, asked structurally of the body - a return, an if/else or a match with a default arm whose every branch ends - rather than handing back whatever the result slot held. The game, the lab and every package example pass all three; the lab had one harmless shadow, and the game's split screens had two real bugs of the kind. examples/rejected/ holds the four refusals, checked by the test runner's new reject_case. Seed regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c57eafcacc
commit
dc75a5a5ab
13 changed files with 46652 additions and 44931 deletions
8
examples/rejected/duplicate_const.ludic
Normal file
8
examples/rejected/duplicate_const.ludic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# duplicate_const.ludic - two files that both define KEY_LEFT. The compiler refuses it and names
|
||||
# both places; it used to keep the first silently, and a game read an arrow key as a binding
|
||||
# slot's number for months. (Rejected on purpose: tools/ludic-cli/test.ludic, reject_case.)
|
||||
program DuplicateConst {
|
||||
const KEY_LEFT: int = 130
|
||||
const KEY_LEFT: int = 2
|
||||
entry { print(KEY_LEFT) }
|
||||
}
|
||||
6
examples/rejected/duplicate_property.ludic
Normal file
6
examples/rejected/duplicate_property.ludic
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# duplicate_property.ludic - one record name defined twice; refused like a duplicate function
|
||||
program DuplicateProperty {
|
||||
property Look { hair: int = 0 }
|
||||
property Look { top: int = 0 }
|
||||
entry { print(1) }
|
||||
}
|
||||
8
examples/rejected/missing_return.ludic
Normal file
8
examples/rejected/missing_return.ludic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# missing_return.ludic - a function with a result that can run off its end. It used to return
|
||||
# whatever the slot held; a split self-test lost its last `return ok` and reported FAILED.
|
||||
program MissingReturn {
|
||||
function checked(n: int) -> bool {
|
||||
if n > 0 { return true }
|
||||
}
|
||||
entry { print(checked(1)) }
|
||||
}
|
||||
9
examples/rejected/redeclared_local.ludic
Normal file
9
examples/rejected/redeclared_local.ludic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# redeclared_local.ludic - one block declaring a name twice. The second used to shadow the first
|
||||
# silently: a settings page compared its vegetation setting against the volumetric one for it.
|
||||
program RedeclaredLocal {
|
||||
entry {
|
||||
let v0 = 1
|
||||
let v0 = 2
|
||||
print(v0)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue