plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
cfca60a
— Peter John
2026-11-01T17:03:41+05:30
fix: name the file in positioned type errors
- plum-cli/src/main.rs +2 -2
- plum-cli/tests/crash_test.rs +1 -1
- plum-wasm-codegen/src/lib.rs +12 -1
plum-cli/src/main.rs
CHANGED
|
@@ -150,7 +150,7 @@ fn compileToWasm(file: &std::path::Path, lib_path: &std::path::Path) -> Result<V
|
|
|
150
150
|
let ast = plum_core::loadAndMerge(file, lib_path).map_err(|e| anyhow::anyhow!("{e}"))?;
|
|
151
151
|
|
|
152
152
|
// Type check once; codegen reuses the result.
|
|
153
|
-
let typed = match plum_wasm_codegen::
|
|
153
|
+
let typed = match plum_wasm_codegen::typeCheckIn(&ast, &file.display().to_string()) {
|
|
154
154
|
Ok(t) => t,
|
|
155
155
|
Err(messages) => {
|
|
156
156
|
eprintln!("{messages}");
|
|
@@ -176,7 +176,7 @@ fn compileToTestWasm(
|
|
|
176
176
|
// dying on the first file with a type error. Checked once, on the
|
|
177
177
|
// test-desugared source codegen then compiles.
|
|
178
178
|
let prog = plum_wasm_codegen::desugarTests(&ast);
|
|
179
|
-
let typed = plum_wasm_codegen::
|
|
179
|
+
let typed = plum_wasm_codegen::typeCheckIn(&prog.source, &file.display().to_string()).map_err(|m| anyhow::anyhow!(m))?;
|
|
180
180
|
let compiled = plum_wasm_codegen::compileTestTyped(&prog, typed)
|
|
181
181
|
.map_err(|e| anyhow::anyhow!("codegen error: {e}"))?;
|
|
182
182
|
// Debug aid: `PLUM_DUMP_WASM=out.wasm plum test file.plum` keeps the module.
|
plum-cli/tests/crash_test.rs
CHANGED
|
@@ -50,5 +50,5 @@ fn int_literal_overflow_error_has_position() {
|
|
|
50
50
|
String::from_utf8_lossy(&out.stderr)
|
|
51
51
|
);
|
|
52
52
|
assert!(all.contains("integer literal out of range"), "output: {all}");
|
|
53
|
-
assert!(all.contains("line 4, column"), "output: {all}");
|
|
53
|
+
assert!(all.contains("lit.plum' at line 4, column"), "output: {all}");
|
|
54
54
|
}
|
plum-wasm-codegen/src/lib.rs
CHANGED
|
@@ -1350,10 +1350,21 @@ fn inferFallbackType(expr: &ast::Expr, ctx: &LocalCtx) -> PlumType {
|
|
|
1350
1350
|
/// Type-checks `source` once, returning the per-expression types codegen needs
|
|
1351
1351
|
/// (`plum_checker::typedSource`) or the joined `type error: ...` lines.
|
|
1352
1352
|
pub fn typeCheck(source: &ast::Source) -> Result<plum_checker::TypedInfo, String> {
|
|
1353
|
+
typeCheckIn(source, "")
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/// Like `typeCheck`, naming `file` in positioned errors. Positions refer to the
|
|
1357
|
+
/// merged source, so imported-file errors are attributed to the entry file.
|
|
1358
|
+
pub fn typeCheckIn(source: &ast::Source, file: &str) -> Result<plum_checker::TypedInfo, String> {
|
|
1353
1359
|
plum_checker::typedSource(source).map_err(|errs| {
|
|
1354
1360
|
errs.iter()
|
|
1355
1361
|
.map(|e| {
|
|
1362
|
+
if e.line > 0 && !file.is_empty() {
|
|
1363
|
+
format!(
|
|
1364
|
+
"type error in '{}' at line {}, column {}: {}",
|
|
1365
|
+
file, e.line, e.column, e.message
|
|
1366
|
+
)
|
|
1356
|
-
if e.line > 0 {
|
|
1367
|
+
} else if e.line > 0 {
|
|
1357
1368
|
format!("type error at line {}, column {}: {}", e.line, e.column, e.message)
|
|
1358
1369
|
} else {
|
|
1359
1370
|
format!("type error: {}", e.message)
|