aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors
AgeCommit message (Collapse)Author
2023-11-07sema: analyze field init bodies in a second passkcbanner
This change allows struct field inits to use layout information of their own struct without causing a circular dependency. `semaStructFields` caches the ranges of the init bodies in the `StructType` trailing data. The init bodies are then resolved by `resolveStructFieldInits`, which is called before the inits are actually required. Within the init bodies, the struct decl's instruction is repurposed to refer to the field type itself. This is to allow us to easily rebuild the inst_map mapping required for the init body instructions to refer to the field type. Thanks to @mlugg for the guidance on this one!
2023-11-06Sema: emit error when pointer to extern function is calledBogdan Romanyuk
2023-11-05Sema: fix error notes with wrong extern typeBogdan Romanyuk
2023-10-31Add compile error test case for union layout depending on pointer alignmentkcbanner
2023-10-23Sema: make `@src().line` comptime-knownAndrew Kelley
Reverts 89cef9f5f731f8f33dc935aac3c21bd57c92900d. Closes #13315
2023-10-18Merge pull request #17524 from Vexu/aro-translate-cAndrew Kelley
Add ability to test Aro based `translate-c`
2023-10-17Sema: disallow `@intFromPtr` for comptime-only typesBogdan Romanyuk
2023-10-17tests: translate-c and run-translated-c to the test harnessVeikka Tuominen
2023-10-16Sema: fix missing check for tuple default initializersVeikka Tuominen
Closes #17525
2023-10-16Sema: fix `@extern` error on function pointerBogdan Romanyuk
2023-10-13drop for loop syntax upgrade mechanismsAndrew Kelley
2023-10-08give modules friendly names for error reportingAndrew Kelley
2023-10-01Sema: add `@errorCast` which works for both error sets and error unionsVeikka Tuominen
Closes #17343
2023-09-23compiler: preserve result type information through address-of operatormlugg
This commit introduces the new `ref_coerced_ty` result type into AstGen. This represents a expression which we want to treat as an lvalue, and the pointer will be coerced to a given type. This change gives known result types to many expressions, in particular struct and array initializations. This allows certain casts to work which previously required explicitly specifying types via `@as`. It also eliminates our dependence on anonymous struct types for expressions of the form `&.{ ... }` - this paves the way for #16865, and also results in less Sema magic happening for such initializations, also leading to potentially better runtime code. As part of these changes, this commit also implements #17194 by disallowing RLS on explicitly-typed struct and array initializations. Apologies for linking these changes - it seemed rather pointless to try and separate them, since they both make big changes to struct and array initializations in AstGen. The rationale for this change can be found in the proposal - in essence, performing RLS whilst maintaining the semantics of the intermediary type is a very difficult problem to solve. This allowed the problematic `coerce_result_ptr` ZIR instruction to be completely eliminated, which in turn also simplified the logic for inferred allocations in Sema - thanks to this, we almost break even on line count! In doing this, the ZIR instructions surrounding these initializations have been restructured - some have been added and removed, and others renamed for clarity (and their semantics changed slightly). In order to optimize ZIR tag count, the `struct_init_anon_ref` and `array_init_anon_ref` instructions have been removed in favour of using `ref` on a standard anonymous value initialization, since these instructions are now virtually never used. Lastly, it's worth noting that this commit introduces a slightly strange source of generic poison types: in the expression `@as(*anyopaque, &x)`, the sub-expression `x` has a generic poison result type, despite no generic code being involved. This turns out to be a logical choice, because we don't know the result type for `x`, and the generic poison type represents precisely this case, providing the semantics we need. Resolves: #16512 Resolves: #17194
2023-09-22AstGen: fix @export with undeclared identifier crashingWooster
This required a third `if (found_already == null)` in another place in AstGen.zig for this special case of `@export`. Fixes #17188
2023-09-19write function types consistently with a space before `fn` keywordr00ster91
Currently, the compiler (like @typeName) writes it `fn(...) Type` but zig fmt writes it `fn (...) Type` (notice the space after `fn`). This inconsistency is now resolved and function types are consistently written the zig fmt way. Before this there were more `fn (...) Type` occurrences than `fn(...) Type` already.
2023-09-15compiler: implement destructuring syntaxmlugg
This change implements the following syntax into the compiler: ```zig const x: u32, var y, foo.bar = .{ 1, 2, 3 }; ``` A destructure expression may only appear within a block (i.e. not at comtainer scope). The LHS consists of a sequence of comma-separated var decls and/or lvalue expressions. The RHS is a normal expression. A new result location type, `destructure`, is used, which contains result pointers for each component of the destructure. This means that when the RHS is a more complicated expression, peer type resolution is not used: each result value is individually destructured and written to the result pointers. RLS is always used for destructure expressions, meaning every `const` on the LHS of such an expression creates a true stack allocation. Aside from anonymous array literals, Sema is capable of destructuring the following types: * Tuples * Arrays * Vectors A destructure may be prefixed with the `comptime` keyword, in which case the entire destructure is evaluated at comptime: this means all `var`s in the LHS are `comptime var`s, every lvalue expression is evaluated at comptime, and the RHS is evaluated at comptime. If every LHS is a `const`, this is not allowed: as with single declarations, the user should instead mark the RHS as `comptime`. There are a few subtleties in the grammar changes here. For one thing, if every LHS is an lvalue expression (rather than a var decl), a destructure is considered an expression. This makes, for instance, `if (cond) x, y = .{ 1, 2 };` valid Zig code. A destructure is allowed in almost every context where a standard assignment expression is permitted. The exception is `switch` prongs, which cannot be destructures as the comma is ambiguous with the end of the prong. A follow-up commit will begin utilizing this syntax in the Zig compiler. Resolves: #498
2023-09-07AstGen: fix missing array type validationVeikka Tuominen
Closes #17084
2023-09-05AstGen: fix error on missing function prototype nameVeikka Tuominen
Closes #17070
2023-08-28Sema: revert reference trace changes that are no longer neededJacob Young
2023-08-28Sema: allow cast builtins on vectorsmlugg
The following cast builtins did not previously work on vectors, and have been made to: * `@floatCast` * `@ptrFromInt` * `@intFromPtr` * `@floatFromInt` * `@intFromFloat` * `@intFromBool` Resolves: #16267
2023-08-22compiler: move unions into InternPoolAndrew Kelley
There are a couple concepts here worth understanding: Key.UnionType - This type is available *before* resolving the union's fields. The enum tag type, number of fields, and field names, field types, and field alignments are not available with this. InternPool.UnionType - This one can be obtained from the above type with `InternPool.loadUnionType` which asserts that the union's enum tag type has been resolved. This one has all the information available. Additionally: * ZIR: Turn an unused bit into `any_aligned_fields` flag to help semantic analysis know whether a union has explicit alignment on any fields (usually not). * Sema: delete `resolveTypeRequiresComptime` which had the same type signature and near-duplicate logic to `typeRequiresComptime`. - Make opaque types not report comptime-only (this was inconsistent between the two implementations of this function). * Implement accepted proposal #12556 which is a breaking change.
2023-08-21Sema: disallow C pointer to slice coercionmlugg
Resolves: #16719
2023-08-21Sema: check @memset operand provides lengthmlugg
Resolves: #16698
2023-08-21AstGen: disallow '-0' integer literalmlugg
The intent here is ambiguous: this resolves to the comptime_int '0', but it's likely the user meant to use a floating-point literal. Resolves: #16890
2023-08-20AstGen: add result location analysis passmlugg
The main motivation for this change is eliminating the `block_ptr` result location and corresponding `store_to_block_ptr` ZIR instruction. This is achieved through a simple pass over the AST before AstGen which determines, for AST nodes which have a choice on whether to provide a result location, which choice to make, based on whether the result pointer is consumed non-trivially. This eliminates so much logic from AstGen that we almost break even on line count! AstGen no longer has to worry about instruction rewriting based on whether or not a result location was consumed: it always knows what to do ahead of time, which simplifies a *lot* of logic. This also incidentally fixes a few random AstGen bugs related to result location handling, leading to the changes in `test/` and `lib/std/`. This opens the door to future RLS improvements by making them much easier to implement correctly, and fixes many bugs. Most ZIR is made more compact after this commit, mainly due to not having redundant `store_to_block_ptr` instructions lying around, but also due to a few bugs in the old system which are implicitly fixed here.
2023-08-15InternPool: preserve indices of builtin types when resolvedmlugg
Some builtin types have a special InternPool index (e.g. `.type_info_type`) so that AstGen can refer to them before semantic analysis. Unfortunately, this previously led to a second index existing to refer to the type once it was resolved, complicating Sema by having the concept of an "unresolved" type index. This change makes Sema modify these InternPool indices in-place to contain the expanded representation when resolved. The analysis of the corresponding decls is caught in `Module.semaDecl`, and a field is set on Sema telling it which index to place struct/union/enum types at. This system could break if `std.builtin` contained complex decls which evaluate multiple struct types, but this will be caught by the assertions in `InternPool.resolveBuiltinType`. The AstGen result types which were disabled in 6917a8c have been re-enabled. Resolves: #16603
2023-08-14Sema: provide source location when analyzing panic handlermlugg
The panic handler decl_val was previously given a `unneeded` source location, which was then added to the reference trace, resulting in a crash if the source location was used in the reference trace. This commit makes two trivial changes: * Don't add unneeded source locations to the ref table (panic in debug, silently ignore in release) * Pass a real source location when analyzing the panic handler
2023-08-12AstGen: fix src loc for invalid switch expression rls coercionsJacob Young
2023-08-12AstGen: fix src loc for invalid coercion in breaksJacob Young
2023-08-12AstGen: fix src loc for invalid coercions in tuple literalsJacob Young
2023-08-12AstGen: fix src loc for invalid if expression rls coercionsJacob Young
Closes #12509
2023-08-10cases: modify error wording to match new errorsmlugg
The changes to result locations and generic calls has caused mild changes to some compile errors. Some are slightly better, some slightly worse, but none of the changes are major.
2023-08-09compiler: fix crash on invalid result type for `@splat`mlugg
This introduces a new ZIR instruction, `vec_elem_type`. Co-Authored-By: Ali Chraghi <alichraghi@proton.me> Resolves: #16567
2023-08-09Module: implement `span` for `.call_arg` of a `@call`Jacob Young
Closes #16750
2023-08-09Sema: fix generic method argument source locationsJacob Young
2023-08-06Add compile error test for comptime slice-of-struct copyStevie Hryciw
Closes #6305. In the C++ implementation this hit a compiler assertion. It is handled properly in the self-hosted version.
2023-08-05Sema: fix issues passing an invalid type to a generic methodJacob Young
Closes #16601
2023-08-02Sema: improve new error messages related to naked functionsJacob Young
* pass a source location to all safety checks * add notes about what is disallowed in naked functions Closes #16651
2023-07-29Allow zero-sized fields in extern structs (#16404)AdamGoertz
This change allows the following types to appear in extern structs: * Zero-bit integers * void * zero-sized structs and packed structs * enums with zero-bit backing integers * arrays of any length with zero-size elements
2023-07-28suggest using else when '_' is used for exhaustive enums (#16583)xdBronch
2023-07-25frontend: forbid packed and extern tuplesAndrew Kelley
2023-07-21fix @embedFile("") not giving a proper errorr00ster91
Currently, in a debug build of the compiler, `@embedFile("")` is a crash; in a release build the compiler, `@embedFile("")` is "error: unable to open '': OutOfMemory".
2023-07-18Sema: fix compile error source location regressionsAndrew Kelley
2023-07-18Sema: fix fn_proto_param LazySrcLoc resolutionAndrew Kelley
to match source code span from merge-base.
2023-07-18Sema: fix crash: array_in_c_exported_functionAndrew Kelley
Fuck it, we're storing decl indexes in LazySrcLoc now.
2023-07-18Sema: enhance generic call error messageAndrew Kelley
when the type of an anytype parameter is a comptime-only type but the argument at the callsite is runtime-known.
2023-07-12Update tests to new splat syntaxantlilja
2023-07-11Fixes crash when a struct is given as the first parameter to the unionInit ↵Anton Lilja
builtin (#16385)
2023-07-11Fixes wrong error location for unionInit when first parameter is not a type ↵Anton Lilja
(#16384)