瀏覽代碼

Language plugin: silence field errors on records without nominal identity

Eric Streit 5 天之前
父節點
當前提交
6d23c80dab
共有 1 個文件被更改,包括 11 次插入 和 3 次删除
  1. 11 3
      extensions/modula2-language/src/m2/checker.ts

+ 11 - 3
extensions/modula2-language/src/m2/checker.ts

@@ -629,7 +629,15 @@ class Walker {
         };
       }
       if (stripped.kind === 'record') {
-        this.issue(nm, `Record "${stripped.name ?? '?'}" has no field "${nm.text}"`);
+        // Report only when the field list is knowable: a nominal record
+        // name, or an inline RECORD declaration on the host symbol.
+        // Anything else (e.g. a type from a sibling or unavailable
+        // definition module) stays silent per the zero-false-positive
+        // rule — hence never `Record "?" ...`.
+        if (stripped.name || /RECORD/i.test(decl.sym.detail)) {
+          const what = stripped.name ? `Record "${stripped.name}"` : 'Record';
+          this.issue(nm, `${what} has no field "${nm.text}"`);
+        }
         return { type: UNKNOWN, decl: null };
       }
       if (stripped.kind !== 'unknown') {
@@ -649,8 +657,8 @@ class Walker {
       this.issue(nm, `Type ${displayType(stripped)} is not a record`);
       return { type: UNKNOWN, decl: null };
     }
-    if (stripped.kind === 'record') {
-      this.issue(nm, `Record "${stripped.name ?? '?'}" has no field "${nm.text}"`);
+    if (stripped.kind === 'record' && stripped.name) {
+      this.issue(nm, `Record "${stripped.name}" has no field "${nm.text}"`);
     }
     return { type: UNKNOWN, decl: null };
   }