Skip to content

错误码参考 ​

YaoXiang 编译器使用错误码标识不同类型的诊断信息。错误码按编号范围分组,每个错误码对应一个特定的错误场景。


E0xxx -- 词法和语法分析 ​

词法分析器(Lexer)和语法分析器(Parser)阶段产生的错误。

错误码模板说明
E0001Invalid character: '{char}'无效字符
E0002Invalid number literal: '{literal}'无效数字字面量
E0003Unterminated string starting at line {line}未终止的字符串
E0004Invalid character literal: '{literal}'无效字符字面量
E0010Expected {expected}, found {found}期望的令牌
E0011Unexpected token: '{token}'意外的令牌
E0012Invalid syntax: {reason}无效语法
E0013Mismatched {bracket_type}: opened at line {open_line}, column {open_col}, not closed不匹配的括号
E0014Missing semicolon after {statement}缺少分号

E1xxx -- 类型检查 ​

类型检查阶段产生的错误,涵盖变量类型、函数调用、模式匹配、泛型实例化、并发语义和错误传播等。

错误码模板说明
E1001Unknown variable: '{name}'未知变量
E1002Expected type '{expected}', found type '{found}'类型不匹配
E1003Unknown type: '{type}'未知类型
E1010Function '{func}' expects {expected} arguments, found {found}参数数量不匹配
E1011Parameter type mismatch: expected '{expected}', found '{found}'参数类型不匹配
E1012Return type mismatch: expected '{expected}', found '{found}'返回类型不匹配
E1013Function not found: '{func}'函数未找到
E1020Cannot infer type for '{expr}'无法推断类型
E1021Type inference conflict: {reason}类型推断冲突
E1030Pattern non-exhaustive: missing patterns {patterns}模式不完整
E1031Unreachable pattern: '{pattern}'不可达模式
E1040Operation '{op}' is not supported for type '{type}'操作不支持
E1041Index out of bounds: valid range is 0..{max}, found {index}索引越界
E1042Field '{field}' not found in struct '{struct}'字段未找到
E1050Logical operation requires boolean operands, found '{left}' and '{right}'需要布尔操作数
E1051Logical NOT requires boolean operand, found '{type}'逻辑 NOT 需要布尔操作数
E1052Cannot dereference type '{type}', expected pointer type无效解引用
E1053Cannot access field on non-struct type '{type}'非结构体字段访问
E1054Condition must be boolean, found '{type}'条件类型不匹配
E1055Constraint type '{type}' can only be used in generic context约束在非泛型上下文中
E1060Expected {expected} type argument(s), found {found}类型参数数量不匹配
E1061Cannot instantiate generic type with given arguments无法实例化泛型
E1081`?` is only allowed inside functions returning Result? 仅允许在返回 Result 的函数内使用
E1082`?` requires a Result expression, found '{type}'? 只能用于 Result 表达式
E1083Result error type mismatch for `?`: expected '{expected}', found '{found}'? 的错误类型不匹配
E1090Type: Type = Type不可言说(彩蛋)
E1091Generic meta-type self-reference is not allowed: '{decl}'无效的泛型元类型
E1062Const generic constraint violation: {reason}const泛型约束违反
E1064Invalid binding position(s) {positions} for function with {total} parameter(s)绑定位置索引无效(RFC-004)
E1095Unknown interface: '{name}'未知接口(RFC-011a)
E1096Interface '{name}' expects {expected} type argument(s), found {found}接口实例化实参个数不符
E1097Interface member '{member}' conflicts with field of type '{type}'接口成员与字段命名冲突
E1098Type '{type}' does not implement '{interface}.{method}'接口方法未实现
E1099Signature mismatch for '{type}.{method}': expected '{expected}', found '{found}'接口方法签名不匹配
E1100Duplicate implementation of '{type}.{method}' (override is not allowed)同签名方法重复实现(覆盖禁止)
E1101Type '{type}' does not implement interface '{interface}' and cannot enter this existential position类型未实现接口(存在类型成员检查)

E2xxx -- 语义分析 ​

语义分析阶段产生的错误,涵盖作用域、变量生命周期、所有权和函数签名解析等。

错误码模板说明
E2001Variable '{name}' is not in scope作用域错误
E2002Duplicate definition: '{name}' is already defined in this scope重复定义
E2003Ownership constraint violated: {reason}所有权错误
E2010Cannot assign to immutable variable '{name}'不可变赋值
E2011Use of uninitialized variable '{name}'使用未初始化变量
E2012Mutability conflict: cannot use mutable reference in immutable context可变性冲突
E2013Cannot shadow existing variable '{name}'变量遮蔽
E2014'{name}' has been moved and cannot be used使用已移动的变量
E2090Invalid signature: {reason}无效签名
E2091Invalid signature: unknown type '{type_name}'签名未知类型
E2092Invalid signature: missing '->'签名缺少箭头
E2093Invalid signature: duplicate parameter '{name}'重复参数名
E2094Invalid signature: generic '{name}' shadows outer generic泛型参数遮蔽
E2095Invalid signature: parameter '{name}' shadows generic参数名遮蔽泛型

E4xxx -- 泛型与特质 ​

泛型约束和特质系统相关错误。

错误码模板说明
E4001Type '{type}' does not satisfy the trait bound '{trait}'泛型约束违反
E4002Trait '{trait}' not found特质未找到
E4003Missing implementation for trait '{trait}' for type '{type}'特质实现缺失
E4004Conflicting trait implementations for '{trait}'特质实现冲突
E4005Associated type '{assoc_type}' not found in '{container}'关联类型未找到

E5xxx -- 模块与导入 ​

模块系统和导入相关错误。

错误码模板说明
E5001Module '{module}' not found模块未找到
E5002Failed to import module '{module}': {reason}导入错误
E5003Export '{export}' not found in module '{module}'导出未找到
E5004Circular dependency detected: {path}循环依赖
E5005Invalid module path: '{path}'无效的模块路径
E5006Duplicate import: '{name}' is already imported重复导入
E5007Module '{module}' exports: {available}模块导出提示

E6xxx -- 运行时 ​

运行时阶段产生的错误。

错误码模板说明
E6001Division by zero in expression: {expr}除零错误
E6003Array index out of bounds: valid range is 0..{max}, found {index}数组索引越界
E6004Stack overflow: recursion depth exceeded limit {limit}栈溢出
E6005Assertion failed: {condition}断言失败
E6006Function not found: '{func}'函数未找到(运行时)
E6007Runtime error: {message}运行时错误

E7xxx -- I/O 与系统 ​

I/O 操作和系统级错误。

错误码模板说明
E7001File not found: '{path}'文件未找到
E7002Permission denied: '{path}'权限被拒绝
E7003I/O error: {reason}I/O 错误
E7004Network error: {reason}网络错误

E8xxx -- 内部编译器错误 ​

编译器内部错误,通常表示编译器本身的 bug。遇到此类错误请在 GitHub Issues 报告。

错误码模板说明
E8001Internal compiler error: {message}内部编译器错误
E8002Unexpected compiler panic: {reason}意外 Panic
E8003Compiler phase error: {phase} - {message}编译器阶段错误

W1xxx -- 警告 ​

死代码检测相关警告。警告不会阻止编译,但表示代码中可能存在的问题。

错误码模板说明
W1001Unused exported function: '{name}'未使用的导出函数
W1002Unused exported type: '{name}'未使用的导出类型
W1003Unused import: '{name}'未使用的导入
W1004Unused exported variable: '{name}'未使用的导出变量
W1005Unused exported method: '{name}'未使用的导出方法
W1063const generic constraint cannot be evaluated: `{constraint}` ({var} = {value})const 泛型约束无法求值
W1080Constraint cannot be proven at compile-time, degraded to runtime check编译期证明降级

共计 118 个诊断码(111 个错误码 + 7 个警告码),以 define_codes! 注册表(src/util/diagnostic/codes/)为权威源;各码的完整注册清单以注册表为准,本页按族列举常见码。