Diagnostics

How Antril reports errors, and what each AN code means - from the lexer, the parser, declarations and bodies - plus the borrow and region errors Larva reports.

Last updated 14 min read Edit on GitHub

On this page

How errors look

The compiler reports each problem with the file, the line and column where it starts, a code and a message:

Antril
Main() { throw 5; }
Terminal
larva build --check
C:\work\App\Program.ant(1,16): error AN2007: only objects are thrown, not a `i32`

The same diagnostics appear in the editor as you type (through larva lsp), and larva build --check reports them without building.

Codes starting with AN come from Antril:

Range From What it checks
AN0001–AN0007 The lexer Characters, comments, numbers, strings.
AN0010–AN0039 The parser The shape of declarations, statements and expressions.
AN1001–AN1105 Declarations Types, members, signatures, inheritance, constants, interop.
AN1400–AN1422 Declarations Access, and variadic templates.
AN2001–AN2145 Bodies Names, types, calls, conversions, statements, patterns.

Errors written in brackets, such as error[ConflictingBorrow], come from Larva, which checks the program after Antril has compiled it: borrows, regions and unsafe operations. They carry a name instead of a number:

Error What it means
ConflictingBorrow A place is used, assigned or borrowed while an exclusive borrow of it lives, or borrowed &mut twice.
MutationThroughSharedReference Something is written through a &T.
ReturnsLocalReference A function returns a reference to its own local.
CopyOfNonCopy A value that cannot be copied is copied through a reference.
RegionEscape An object made in a region is still used after the region ends.
UnsafeRequired An unsafe operation (such as delete) outside unsafe code.

The borrow errors are warnings with borrowcheck: warn (warning[ConflictingBorrow]) and do not stop the build; see Memory. Antril's own diagnostics are all errors.

The tables below list the codes you are likely to meet. The message itself always says more, with the names involved.

Lexer

Code Meaning
AN0001 A character that is not part of Antril.
AN0002 A /* comment without its */.
AN0003 An invalid number: no digits, or a float written in hexadecimal or binary.
AN0004 A string without its closing " on the same line.
AN0005 An invalid character literal: empty or unclosed.
AN0006 A lone } in an interpolated string: write }}.
AN0007 An interpolation hole without its closing }.

Parser

Code Meaning
AN0010 Something expected is missing: ';', ')', a name…
AN0012, AN0016 A token that cannot start a member or a statement there.
AN0013 The same modifier twice.
AN0014 Modifiers or attributes not followed by a declaration.
AN0015 Something other than get or set inside a property.
AN0017 A loop (…; …; …) without ; between its condition and its step.
AN0018 A try with neither catch nor finally.
AN0019 An expression is expected.
AN0020 A function written with its result first: write Name(…) : T.
AN0021 An invalid operator symbol, a reserved one (=, ., =>, ?, .., ..=, ->, ...), or the wrong number of operands.
AN0022 An operator declared outside a type: operators are members of the type of an operand.
AN0023 An operator without a result type.
AN0024 A base get or base set accessor with a body.
AN0025 left or right on an operator with two operands, or on a conversion.
AN0026 A conversion op (T)(…) with more than one operand.
AN0027 A symbol declared with associativity(Associativity.None) chained: write parentheses.
AN0028 fixed(N) in a constraint without a positive number of bytes.
AN0029 An extension that names a receiver when static, or none when not.
AN0030 reactive, computed or reacts outside a class.
AN0031 reactive, computed or reacts with static, or two of them together.
AN0032 computed with accessors, or reactive on a property.
AN0033 A reacts method with parameters, a result, or no body.
AN0034 An import list without from, or a different number of aliases and names.
AN0035 const not followed by a local declaration.
AN0036 from on a static loop that is not among a type's members, or not followed by a small number.
AN0037 A tuple type of one type: (i32).
AN0038 Two access words on one declaration.
AN0039 into namespace in the header of a member of a type.

Declarations

Types and inheritance

Code Meaning
AN1001 Something other than a type, function or field at the top level.
AN1002 A type declared twice with the same full name.
AN1006 An enum base that is not an integer type, str or a value.
AN1008 A second base that is not an interface (a class has one base class, first), or a base class on something that is not a class.
AN1009 Deriving from a final class.
AN1010 A type that inherits from itself.
AN1012 The wrong number of type arguments.
AN1013 str or any without the core library.
AN1014 An unknown type name.
AN1015, AN2021 An array of more than 8 dimensions.
AN1016 A type that cannot be nullable.
AN1019 An enum member's value that cannot be computed (it divides by zero, or a value-based member has none).
AN1032 A constructor in a type that is not a class or a value.
AN1034 A class that leaves methods of its base classes or interfaces without a body.
AN1035 More than one Main.
AN1043 A property in a type that is not a class, value or interface.
AN1045 A type that implements an interface but lacks one of its methods, properties or operators.
AN1063 An enum with more than one base.
AN1064 A bitflag enum whose base is not an integer type.
AN1076 A record class with a base class, or a class derived from a record class.
AN1077 destroy() in a value, interface or enum.
AN1079 An object of a library built for another gc: mode is used.
AN1096 An attribute or exception whose base is not an attribute or exception, or a program without the core library's Attribute / Exception.
AN1105 A static class used as the type of a variable, field, parameter, result, element, type argument or cast.

Members

Code Meaning
AN1020 A field declared twice.
AN1021, AN1023 A void field or parameter.
AN1022 A static field of a generic type that does not start with a constant.
AN1024 Two parameters with the same name.
AN1026 An async function without a body.
AN1027 A function without a body where one is needed (only instance methods of a base class, and interface methods, may leave it out).
AN1029 virtual or override on something that is not an instance method of a class.
AN1030 Two methods with the same name and parameters.
AN1031 A name used both for a field or property and for a method.
AN1033 Two constructors with the same parameters.
AN1036 override on a method that overrides nothing.
AN1037 An override with a different result type.
AN1038 A method that replaces a virtual one without saying override.
AN1039 Overriding a final method.
AN1044 A property without get.
AN1047 base get / base set outside an interface.
AN1048, AN1049, AN1050 A static constructor with parameters or a call to another constructor; two of them; one in a generic type.
AN1074 A fixed field that is static.
AN1075 Fields, properties or constructors in an extension block, or a parameter named like the receiver.
AN1078 A destructor that is static, or has parameters, a result or type parameters.
AN1097, AN1098, AN1099 An array kept in the object (fixed T[]) in the wrong place, without : fixed(n) in a constructor, or used as an array value.
AN1100 virtual in a type nothing can derive from.
AN1101 final on a method without override.
AN1102 virtual, override or final on a field.
AN1103 A field in a namespace: make it a const, or put it in a type.
AN2131 A parameter of a bodiless constructor that names no field and is not passed to : base(…).

Constants and fixed sizes

Code Meaning
AN1073 A fixed array length that is not a positive constant, sizeof(T) or N * sizeof(T).
AN1086 const with static, readonly, fixed or reactive.
AN1087 A constant without a value.
AN1088 A type that cannot be a constant (arrays, classes).
AN1089 A constant value not made of constants.
AN1090 Constants that depend on each other in a cycle.
AN1091 A constant whose value is not known when compiling.

Operators

Code Meaning
AN1065 A symbol declared again with another precedence or associativity.
AN1066 A precedence on a built-in symbol, which keeps its own.
AN1067 A new binary symbol without a precedence.
AN1068 A precedence on an operator with one operand.
AN1069 A precedence that is not a level of PrecedenceLevel, a number, or a constant enum member.
AN1072 An operator's type parameter that appears in no operand.

Imports, access and templates

Code Meaning
AN1084 An import of a namespace that does not exist, or of a name it does not have.
AN1085 A name imported twice.
AN1092 A reference type (&T) while the borrow checker is off.
AN1093 An access word that does not apply in a namespace (inherited, friendly; private on a type).
AN1094 inherited on a member of a type nothing can derive from: write private.
AN1095 An access word on an interface member.
AN1104 Unsafe code or a pointer type in a project with unsafe: deny.
AN1400, AN1401 A type or member used where its access does not allow it.
AN1420 A type parameter pack (T...) that is not the last, or a static loop outside a variadic template.
AN1421 A pack used as a single type.
AN1422 A static loop over a pack other than the template's.

Attributes and interop

Code Meaning
AN1003, AN1004 [Primitive] misused (core library only).
AN1040 A constraint that names something other than an interface or class.
AN1042 An extern runtime service with a body or type parameters (core library only).
AN1046 A constraint word whose interface needs the core library.
AN1051, AN1052 [Import] on a function with a body or type parameters, or without the library's name.
AN1053, AN1054 An imported function taking or giving a type C cannot hold.
AN1055, AN1056 [Export] on something that is not a static function with a body, or with types C cannot hold.
AN1057 A func* type with parameters or a result C cannot hold.
AN1058, AN1059, AN1060 An attribute that is not an attribute class, is abstract, or has no constructor for these arguments.
AN1061, AN1062 Name = value in an attribute naming no field or property, or not a constant.
AN1070, AN1071 [FriendOf] that does not name one type, or names the type itself.
AN1080–AN1083 [ValueLayout] / [FieldOffset] misused (see Interop).

Bodies

Names and members

Code Meaning
AN2002 base in a type without a base class.
AN2003 A local declared twice in the same scope.
AN2004 A local named like a parameter.
AN2029 this in a static function.
AN2030, AN2047 base used other than to call a base method (base.Name(…)).
AN2031 A method used without calling it.
AN2032 A type used as a value.
AN2033 An unknown name.
AN2034, AN2046 An instance field or method used in a static function.
AN2036, AN2050 An instance member used through the type, or a type without that function.
AN2037, AN2092 A static member a type parameter's constraint does not declare.
AN2038, AN2054 A static member used through a value: write Type.Member.
AN2039 A type without that member.
AN2040 A member read on a value that may be null: check it first (is, ??, ?.).
AN2045 An unknown function.
AN2048, AN2049 base.M() where no base has M, or its M has no body.
AN2051 A namespace without that function.
AN2052, AN2053 A type with no methods, or without that method.
AN2091 A generic type's static member read without its type arguments.
AN2141 nameof of something that is not one existing name.

Calls and constructors

Code Meaning
AN2056 A function value called with the wrong number of arguments.
AN2057 No overload takes these argument types.
AN2058 Two overloads fit equally well: cast an argument.
AN2059 new on something that is not a class or value.
AN2060 new on a static class.
AN2061 new on a base class.
AN2062 new with arguments on a type without such a constructor.
AN2093 Type arguments that cannot be inferred: write them.
AN2094, AN2101, AN2102, AN2124–AN2128 A type argument that does not meet its parameter's constraint.
AN2100 A lambda parameter whose type cannot be inferred: write it.
AN2125 new T(…) without a T : new(…) constraint.

Types and conversions

Code Meaning
AN2008, AN2009 return with a value in a function that returns nothing, or without one in a function that returns something.
AN2001 A function or lambda that does not return a value on every path.
AN2015 A void variable.
AN2016 A variable without a value, of a type with no default.
AN2020 as between types that are not object types.
AN2022 new T[n] of a type with no zero value: use T?.
AN2023, AN2044 An array length or index that is not an integer.
AN2024 An empty array literal with no type to take.
AN2028 A literal that does not fit its suffix's type.
AN2042, AN2043 Indexing something that cannot be indexed, or with the wrong number of indexes.
AN2063, AN2064, AN2065 -, ~, ++ or -- on a type that does not have them.
AN2070 Assigning a readonly field outside its constructors.
AN2071, AN2140 Assigning a constant, or part of one.
AN2072 Assigning something that is not a variable, field, element or property.
AN2073, AN2074, AN2076, AN2078 An operator on types it does not work on.
AN2075 Comparing with null a value that is never null.
AN2079 ?? on a left side that is never null.
AN2080 ?: branches with no type in common.
AN2081 null where the type is not nullable.
AN2082 A downcast to a nullable type: cast to T, or test with as.
AN2084 A value that does not convert to the type expected (a cast may be needed).
AN2095 Assigning a property without set.
AN2097, AN2138 A record field with no ToString() or Hash().
AN2098 + on strings without the core library.
AN2099 x op= v where op does not give x's type.
AN2123 No type of the operands declares this operator for them.
AN2132, AN2133 with on something that is not a record, or naming a field it does not have.
AN2134 == on a nullable record without testing for null.
AN2142, AN2143 A tuple size without the core library, or null in a tuple with no type to take.

Statements

Code Meaning
AN2006 throw; outside a catch.
AN2007 Throwing something that is not an object.
AN2010 break outside a loop or switch.
AN2011 continue outside a loop.
AN2012 delete of something that is not a class object.
AN2014 A loop counter that is not an integer.
AN2017 A catch of a type that is not an object type.
AN2026 A range outside a loop or a pattern.
AN2110–AN2113 yield misused (see Iterators).
AN2114–AN2117 async and await misused (see Async).

Patterns

Code Meaning
AN2085 A switch expression with no arms.
AN2086 <, >… in a pattern on a type that is not a number.
AN2088, AN2089 A type pattern that can never match.
AN2090 A constant pattern of the wrong type.
AN2135, AN2136 A positional pattern with the wrong number of positions, or on a type without positions.
AN2137 A property pattern naming a member the type does not have.

Unsafe code, references and interop

Code Meaning
AN2066 &x (an address) outside unsafe code.
AN2067 *p or p[i] through a pointer outside unsafe code.
AN2068 * on something that is not a pointer.
AN2083 A pointer cast outside unsafe code.
AN2118 &F that does not name exactly one fitting static function.
AN2119 &F of a function whose types C cannot hold.
AN2120 Calling a func* outside unsafe code.
AN2121 Pointer arithmetic outside unsafe code.
AN2122 An operator a pointer does not have (p * 2).
AN2144 &x or &mut x while the borrow checker is off.
AN2145 & of something that is not a place (a local, parameter, field or element).

Other

Code Meaning
AN2018 A character literal of more than one character.
AN2019, AN2025 nameof or typeof without the core library.
AN2027 GetLength without its dimension.
AN2139 $resource("name") naming no resource of the project's RESOURCES chunk.

A few codes say that a construct "comes in a later phase" (AN1018, AN2013, AN2055, AN2069, AN2077, AN2087, AN2096): the compiler recognizes it but does not compile it yet. AN9999 is an internal error of the compiler; please report it with the code that causes it.

Was this page helpful?

No address is stored; your user name is, if you are signed in.

Esc