plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
59fd900
— Peter John
2026-11-10T20:12:48+05:30
Checker: `struct S[T](x: T)` is one error, with the hint
compiler/checker/src/declchecks.rs
CHANGED
|
@@ -247,12 +247,13 @@ pub(crate) fn checkUnknownTypes(source: &ast::Source) -> Vec<CheckError> {
|
|
|
247
247
|
for v in &e.variants {
|
|
248
248
|
v.fields.iter().for_each(|t| walk(t, &sc, &known, &mut bad));
|
|
249
249
|
}
|
|
250
|
-
// An entry that names no trait is reported as that (`struct S[T](
|
|
250
|
+
// An entry that names no trait is reported as that (`struct S[T](x: T)`, with
|
|
251
|
-
// the hint for type parameters)
|
|
251
|
+
// the hint for type parameters), and so are the fields that use the name.
|
|
252
252
|
for t in &e.implements {
|
|
253
253
|
t.generics.iter().for_each(|g| walk(g, &sc, &known, &mut bad));
|
|
254
254
|
}
|
|
255
|
+
let listed = |n: &String| e.implements.iter().any(|t| &t.name == n);
|
|
255
|
-
for n in bad.into_iter().filter(|n| n != ast::SELF_TYPE) {
|
|
256
|
+
for n in bad.into_iter().filter(|n| n != ast::SELF_TYPE && !listed(n)) {
|
|
256
257
|
errors.push(CheckError::at(e.line, e.column, format!("{}: unknown type {}", e.name, n)));
|
|
257
258
|
}
|
|
258
259
|
}
|
compiler/checker/tests/checker/review_tests.rs
CHANGED
|
@@ -184,3 +184,13 @@ fn an_enum_or_unknown_name_with_fields_is_no_constructor() {
|
|
|
184
184
|
errorWith("enum E =\n | A(n: Int)\n | B(s: Int)\n\nfun k(e: E) -> E = E(..e, n: 3)", "'E' is an enum: build one of its variants (A, B)");
|
|
185
185
|
errorWith("fun k() -> Int =\n x := Foo(a: 1)\n 1", "unknown type or variant 'Foo'");
|
|
186
186
|
}
|
|
187
|
+
|
|
188
|
+
/// `struct S[T](x: T)`, the old place of type parameters, is one error with the hint, not
|
|
189
|
+
/// an "unknown type T" line first.
|
|
190
|
+
#[test]
|
|
191
|
+
fn old_type_parameters_in_brackets_are_one_error() {
|
|
192
|
+
let es = run("struct S[T](x: T)").expect_err("an error");
|
|
193
|
+
let ms: Vec<&String> = es.iter().map(|e| &e.message).collect();
|
|
194
|
+
assert!(ms.iter().any(|m| m.contains("T is not a trait") && m.contains("`S<T>`")), "{ms:?}");
|
|
195
|
+
assert!(!ms.iter().any(|m| m.contains("unknown type T")), "{ms:?}");
|
|
196
|
+
}
|