plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
96af2f4
— Peter John
2026-11-10T12:33:55+05:30
Checker: a generic main is an error, not a codegen panic
compiler/checker/src/fncheck.rs
CHANGED
|
@@ -5,6 +5,10 @@ use crate::*;
|
|
|
5
5
|
/// The rule violation of an `export fun` (it has the `extern` boundary ABI, so it
|
|
6
6
|
/// can't be a method or generic), if any.
|
|
7
7
|
pub(crate) fn exportFnError(f: &ast::Fn, ctx: &CheckCtx) -> Option<CheckError> {
|
|
8
|
+
// `main` is the program's entry: the host calls it, so nothing gives it type arguments.
|
|
9
|
+
if !f.is_export && f.type_param.is_none() && f.name == "main" && !fnGenericNames(f, ctx).is_empty() {
|
|
10
|
+
return Some(CheckError::at(f.line, f.column, "fn 'main': main can't be generic".to_string()));
|
|
11
|
+
}
|
|
8
12
|
if !f.is_export {
|
|
9
13
|
return None;
|
|
10
14
|
}
|
compiler/checker/tests/checker/diagnostic_tests.rs
CHANGED
|
@@ -234,3 +234,13 @@ fn rightTypeArgumentCountStillReportsAMismatch() {
|
|
|
234
234
|
assert_eq!(es.len(), 1, "{es:?}");
|
|
235
235
|
assert!(es[0].message.contains("mismatch"), "{es:?}");
|
|
236
236
|
}
|
|
237
|
+
|
|
238
|
+
/// A generic `main` has no caller to give it type arguments: an error at its declaration
|
|
239
|
+
/// (codegen used to panic, "entry fn is a registered unit").
|
|
240
|
+
#[test]
|
|
241
|
+
fn genericMainIsAnError() {
|
|
242
|
+
let es = errors("fun main[T]() -> Int = 1\n");
|
|
243
|
+
assert_eq!(es.len(), 1, "{es:?}");
|
|
244
|
+
assert_eq!((es[0].line, es[0].column), (1, 1), "{es:?}");
|
|
245
|
+
assert!(es[0].message.contains("main can't be generic"), "{es:?}");
|
|
246
|
+
}
|