浏览代码

chore: Added Custom error when using init on SystemAccount (#3828)

* Add error when using init on SystemAccount

* error fix

* add descriptive error message
Nalin Khanna 1 月之前
父节点
当前提交
3afd82e082
共有 1 个文件被更改,包括 13 次插入0 次删除
  1. 13 0
      lang/syn/src/parser/accounts/mod.rs

+ 13 - 0
lang/syn/src/parser/accounts/mod.rs

@@ -93,6 +93,19 @@ fn constraints_cross_checks(fields: &[AccountField]) -> ParseResult<()> {
         })
         })
         .collect();
         .collect();
 
 
+    for field in &init_fields {
+        if matches!(field.ty, Ty::SystemAccount) {
+            return Err(ParseError::new(
+                field.ident.span(),
+                "Cannot use `init` on a `SystemAccount`. \
+                    The `SystemAccount` type represents an already-existing account \
+                    owned by the system program and cannot be initialized. \
+                    If you need to create a new account, use a more specific account type \
+                    or `UncheckedAccount` and perform manual initialization instead.",
+            ));
+        }
+    }
+
     if !init_fields.is_empty() {
     if !init_fields.is_empty() {
         // init needs system program.
         // init needs system program.