Skip to content

Commit 0f1c63d

Browse files
committed
Cover Option lowering path
1 parent 619b7c2 commit 0f1c63d

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ If a lowered package contains `fn main() -> Unit` or `fn main() -> Result<Unit,
418418

419419
`rss verify-rust <file.rss> --out-dir <directory>` keeps the generated package used for backend checking, including `rsscript-source-map.json`, so unmappable rustc diagnostics can be inspected against the generated Rust.
420420

421-
The first observable runtime boundaries are `Log.write(message: read String)` and `Assert.equal(left: read String, right: read String)`, which lower to explicit runtime hooks. Simple core operations such as `String.concat(left: read String, right: read String)` keep RSScript `.rssi` signatures for checking and review, but lower directly to Rust standard-library expressions. Built-in boolean literals, numeric operators, and comparison operators lower to the corresponding Rust literals and operators; user-defined operator overloading remains forbidden.
421+
The first observable runtime boundaries are `Log.write(message: read String)` and `Assert.equal(left: read String, right: read String)`, which lower to explicit runtime hooks. Simple core operations such as `String.concat(left: read String, right: read String)` keep RSScript `.rssi` signatures for checking and review, but lower directly to Rust standard-library expressions. Built-in boolean literals, numeric operators, comparison operators, and `Option<T>` constructors lower to the corresponding Rust literals, operators, and enum constructors; user-defined operator overloading remains forbidden.
422422

423423
Smallest runnable example:
424424

examples/option.rss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub fn maybe_value(flag: Bool) -> Option<Int> {
2+
if flag {
3+
return Some(42)
4+
}
5+
return None
6+
}
7+
8+
fn main() -> Unit {
9+
let _ = maybe_value(flag: true)
10+
Log.write(message: read "option ran")
11+
return Unit
12+
}

tests/checker.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ pub fn unit_result() -> Result<Unit, BuildError> {
265265
assert!(rust.contains("return Ok(());"));
266266
}
267267

268+
#[test]
269+
fn rust_lowering_maps_option_type_and_constructors_to_rust() {
270+
let source = r#"
271+
pub fn maybe_value(flag: Bool) -> Option<Int> {
272+
if flag {
273+
return Some(42)
274+
}
275+
return None
276+
}
277+
"#;
278+
let rust = lower_source_to_rust("option.rss", source).expect("source should lower");
279+
280+
assert!(rust.contains("pub fn maybe_value(flag: bool) -> Option<i64>"));
281+
assert!(rust.contains("return Some(42);"));
282+
assert!(rust.contains("return None;"));
283+
}
284+
268285
#[test]
269286
fn rust_lowering_maps_log_write_to_runtime_output_hook() {
270287
let source = r#"

0 commit comments

Comments
 (0)