Skip to content

Semantic Rules Catalog

This document enumerates semantic rules derived from the language spec. Rules are grouped by stage to enable incremental implementation. Each rule includes a code, severity, and intent. Adjust codes as needed.

Stage 0: Definition & Signature Collection

Section titled “Stage 0: Definition & Signature Collection”
  • Trigger: two type/enum/contract items share the same name in a module.
  • Source: 02-types, 09-contracts, 10-name-resolution.
  • Trigger: enum defines the same variant name twice.
  • Source: 04-enums-and-match.
  • Trigger: contract defines duplicate method signatures.
  • Source: 09-contracts.
  • Trigger: embedded contracts introduce conflicting methods (same name, incompatible signature).
  • Source: 09-contracts (conflict example).
  • Trigger: field/parameter types reference unknown type names.
  • Source: 02-types, 10-name-resolution.
  • Trigger: duplicate function/module/use item name in the same module scope.
  • Source: 10-name-resolution.
  • Trigger: identifier used in expression has no binding in scope.
  • Source: 10-name-resolution.
  • Trigger: let/parameter binding duplicates a name in the same scope.
  • Source: 10-name-resolution.
  • Trigger: binding shadows a name from an outer scope.
  • Source: 10-name-resolution.
  • Trigger: two use imports bring the same name without aliasing.
  • Source: 10-name-resolution (ambiguous import error).
  • Trigger: use path does not resolve to a module/item.
  • Source: 06-modules-and-visibility, 10-name-resolution.
  • Trigger: use of local binding before its declaration (if enforced).
  • Source: 10-name-resolution (lexical scopes).
  • Trigger: type annotation refers to non-existent type.
  • Source: 02-types.
  • Trigger: cannot infer local/private function return type (multiple incompatible returns).
  • Source: 11-type-inference.
  • Trigger: public function missing explicit return type.
  • Source: 11-type-inference.
  • Trigger: call has wrong number of arguments.
  • Source: 01-lexical-and-syntax, 02-types.
  • Trigger: argument type not assignable to parameter type.
  • Source: 02-types.
  • Trigger: RHS not assignable to LHS type.
  • Source: 02-types.
  • Trigger: return expression type does not match function return type.
  • Source: 02-types.
  • Trigger: if/while condition is not bool.
  • Source: 05-control-flow.
  • Trigger: binary operator operands are incompatible.
  • Source: 02-types.
  • Trigger: unary operator applied to invalid type.
  • Source: 02-types.
  • Trigger: struct literal includes unknown field.
  • Source: 02-types.
  • Trigger: struct literal omits required fields.
  • Source: 02-types.
  • Trigger: member access on non-struct value.
  • Source: 02-types.
  • Trigger: assignment to immutable binding (missing mut).
  • Source: 02-types (mutability rules).
  • Trigger: value used after move (non-copy type).
  • Source: 02-types (move semantics).
  • Trigger: == operands are not comparable or have incompatible types.
  • Source: 02-types (equality semantics).
  • Trigger: === used on non-reference operands.
  • Source: 02-types (reference identity).
  • Trigger: out argument is not a mutable binding.
  • Source: 03-memory-and-references.
  • Trigger: ref/out arguments are not assignable lvalues.
  • Source: 03-memory-and-references.
  • Trigger: enum constructor references unknown enum/variant.
  • Source: 04-enums-and-match.

E1302 EnumConstructorArityMismatch (Error)

Section titled “E1302 EnumConstructorArityMismatch (Error)”
  • Trigger: enum constructor called with wrong number of arguments.
  • Source: 04-enums-and-match.
  • Trigger: enum constructor invoked without Enum:: qualifier.
  • Source: 04-enums-and-match.
  • Trigger: match does not cover all variants (and no _).
  • Source: 04-enums-and-match.
  • Trigger: match arm expression types differ.
  • Source: 04-enums-and-match.
  • Trigger: pattern binds same name multiple times.
  • Source: 04-enums-and-match.
  • Trigger: enum pattern has wrong number of subpatterns.
  • Source: 04-enums-and-match.
  • Trigger: when guard is not bool.
  • Source: 04-enums-and-match.
  • Trigger: break used outside loop.
  • Source: 05-control-flow.
  • Trigger: continue used outside loop.
  • Source: 05-control-flow.
  • Trigger: statement after return/break/continue in same block.
  • Source: 05-control-flow.
  • Trigger: access to non-pub item from another module.
  • Source: 06-modules-and-visibility.
  • Trigger: mod declaration refers to a missing module file.
  • Source: 06-modules-and-visibility.
  • Trigger: use path never referenced.
  • Source: 06-modules-and-visibility.
  • Trigger: private item declared but never used in module.
  • Source: 06-modules-and-visibility.
  • Trigger: an explicitly declared type Type : Contract conformance is missing one or more required contract methods in impl Type blocks.
  • Source: 09-contracts.

E1602 ContractImplSignatureMismatch (Error)

Section titled “E1602 ContractImplSignatureMismatch (Error)”
  • Trigger: method implementation in impl Type for a declared type Type : Contract conformance does not match contract signature.
  • Source: 09-contracts.
  • Trigger: overloaded methods resolve ambiguously.
  • Source: 12-method-dispatch.
  • Trigger: ref receiver does not satisfy contract method set.
  • Source: 12-method-dispatch.

E1605 MethodLookupWithAliasFailure (Error)

Section titled “E1605 MethodLookupWithAliasFailure (Error)”
  • Trigger: method resolution fails due to alias target mismatch.
  • Source: 12-method-dispatch, 10-name-resolution.
  • Trigger: method call cannot be resolved for receiver type.
  • Source: 12-method-dispatch.
  • Trigger: value typed as contract has no explicit conformance declaration (type Type : Contract) for the required contract.
  • Source: 09-contracts, 12-method-dispatch.
  • Trigger: ? used on non-Result type.
  • Source: 07-error-handling.
  • Trigger: ? used where error type is incompatible with function return type.
  • Source: 07-error-handling.
  • Trigger: ? used outside a function body.
  • Source: 07-error-handling.
  • Trigger: attribute application references no declared attribute.
  • Source: 01-lexical-and-syntax.
  • Trigger: attribute application passes an argument not present in attribute declaration.
  • Source: 01-lexical-and-syntax.

E1803 AttributeMissingRequiredArgument (Error)

Section titled “E1803 AttributeMissingRequiredArgument (Error)”
  • Trigger: required attribute parameter (without default) is not provided.
  • Source: 01-lexical-and-syntax.
  • Trigger: same named argument provided more than once in attribute application.
  • Source: 01-lexical-and-syntax.

E1805 AttributeArgumentTypeMismatch (Error)

Section titled “E1805 AttributeArgumentTypeMismatch (Error)”
  • Trigger: argument expression type does not match declared parameter type.
  • Source: 01-lexical-and-syntax.

E1806 DuplicateAttributeDeclarationTarget (Error)

Section titled “E1806 DuplicateAttributeDeclarationTarget (Error)”
  • Trigger: attribute declaration target list repeats the same target kind more than once.
  • Source: 01-lexical-and-syntax.

E1807 UnknownAttributeDeclarationTarget (Error)

Section titled “E1807 UnknownAttributeDeclarationTarget (Error)”
  • Trigger: attribute declaration target list uses an unsupported target kind.
  • Source: 01-lexical-and-syntax.
  • Trigger: attribute application site node kind is not included in attribute declaration target list.
  • Source: 01-lexical-and-syntax.
  • Generator-specific metaprogramming diagnostics are tracked in: docs/guides/drafts/metaprogramming/semantic-rules.md.
  • Rules marked Warning can be toggled via AnalysisOptions.
  • Some rules (question operator) may be deferred if v0.1 parser/AST doesn’t yet support them.