aboutsummaryrefslogtreecommitdiff
path: root/test/compile_errors.zig
AgeCommit message (Collapse)Author
2022-02-01stage2: remove anytype fields from the languageAndrew Kelley
closes #10705
2022-02-01stage1: avoid anytype fields for type infoAndrew Kelley
prerequisite for #10705
2022-01-31update behavior tests and compile error testsAndrew Kelley
2022-01-20stage1: remove the "referenced here" error noteAndrew Kelley
It's generally noise. The parts where it is useful will need to be redone to not be annoying for the general case.
2021-12-27AstGen: fix loop result locationsAndrew Kelley
The main problem was that the loop body was treated as an expression that was one of the peer result values of a loop, when in reality the loop body is noreturn and only the `break` operands are the result values of loops. This was solved by introducing an override that prevents rvalue() from emitting a store to result location instruction for loop bodies. An orthogonal change also included in this commit is switching `elem_val` index expressions to using `coerced_ty` and doing the coercion to `usize` inside `Sema`, resulting in smaller ZIR (since the cast becomes implied). I also changed the break operand expression to use `reachableExpr`, introducing a new compile error for double break. This makes a few more behavior tests pass for `while` and `for` loops.
2021-12-19stage1, stage2: rename c_void to anyopaque (#10316)Isaac Freund
zig fmt now replaces c_void with anyopaque to make updating code easy.
2021-12-08stage1: fix regression of shift by negative value errorAndrew Kelley
The previous commit (38b2d6209239f0dad7cb38e656d9d38506f126ca) regressed the compile error test case for when doing saturating shift left of a comptime-known negative RHS. This commit additionally fixes the error for regular shifts in addition to saturating shifts.
2021-12-02parse.zig: make chained comparison operators a parse errorMatthew Borkowski
2021-11-30allocgate: fix failing testsLee Cannon
2021-11-30allocgate: stage 1 and 2 buildingLee Cannon
2021-11-29AstGen: require binary operations to have reachable operandsAndrew Kelley
2021-11-27stage2: implement `@typeName`Andrew Kelley
* stage1: change the `@typeName` of `@TypeOf(undefined)`, `@TypeOf(null)`, and `@TypeOf(.foo)` to match stage2. * move passing behavior tests to the passing-for-stage2 section.
2021-11-25stage1: fix exporting enumsAndrew Kelley
After extern enums were removed, stage1 was left in an incorrect state of checking for `extern enum` for exported enums. This commit fixes it to look for an explicit integer tag type instead, and adds test coverage for the compile error case as well as the success case. closes #9498
2021-11-24stage2: fix cleanup code for `@import` errorsAndrew Kelley
When adding test coverage, I noticed an inconsistency in which source location the compile error was pointing to for `@embedFile` errors vs `@import` errors. They now both point to the same place, the string operand. closes #9404 closes #9939
2021-11-24stage2: add test coverage for `@embedFile` outside package pathAndrew Kelley
closes #6662
2021-11-24AstGen: use reachableExpr for return operandAndrew Kelley
Related: #9630
2021-11-22stage1: improve packed struct array padding error messageKirk Scheibelhut
2021-10-15Sat shl neg rhs (#9949)travisstaloch
* saturating shl - check for negative rhs at comptime - adds expected compile_errors case for negative rhs * add expected compile error for sat shl assign
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
2021-09-28saturating arithmetic supports integers onlyAndrew Kelley
2021-09-24Spelling corrections (#9833)Josh Soref
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2021-09-20Address Spaces: Yeet address space on function prototypesRobin Voetter
This is a property which solely belongs to pointers to functions, not to the functions themselves. This cannot be properly represented by stage 2 at the moment, as type with zigTypeTag() == .Fn is overloaded for for function pointers and function prototypes.
2021-09-20Address Spaces: Adapt compile error test cases to @Type with address spacesRobin Voetter
2021-09-20Address Spaces: Pointer and function info in @TypeRobin Voetter
2021-09-01std.os fixes to get the test suite passing againAndrew Kelley
2021-09-01stage2: first pass at implementing usingnamespaceAndrew Kelley
Ran into a design flaw here which will need to get solved by having AstGen annotate ZIR with which instructions are closed over.
2021-09-01saturating arithmetic builtins: add, sub, mul, shl (#9619)travisstaloch
- adds 1 simple behavior tests for each which does integer and vector ops at runtime and comptime - adds bigint_*_sat() methods for each - use CreateIntrinsic() which accepts a variable number of arguments to pass the scale parameter * update langref - added case to test/compile_errors.zig given floats - explain upstream bug in llvm.smul.fix.sat and link to #9643 in langref and commented out test cases * sat-arithmetic: skip mul tests if arch == .wasm32 because ci is erroring with 'LLVM ERROR: Unable to expand fixed point multiplication' when compiling for wasm32
2021-08-28AstGen: pre-scan all decls in a namespaceAndrew Kelley
Also: * improve the "ambiguous reference" error by swapping the order of "declared here" and "also declared here" notes. * improve the "not accessible from inner function" error: - point out that it has to do with the thing being mutable - eliminate the incorrect association with it being a function - note where it crosses a namespace boundary * struct field types are evaluated in a context that has the struct namespace visible. Likewise with align expressions, linksection expressions, enum tag values, and union/enum tag argument expressions. Closes #9194 Closes #9622
2021-08-28AstGen: allow locals with same name as primitives with `@""` syntaxAndrew Kelley
This makes local names follow the same rule as declaration names.
2021-08-27declarations may collide with primitives with @"" syntaxAndrew Kelley
* stage2 AstGen: add missing compile error for declaring a local that shadows a primitive. Even with `@""` syntax, it may not have the same name as a primitive. * stage2 AstGen: add a compile error for a global declaration whose name matches a primitive. However it is allowed when using `@""` syntax. * stage1: delete all "declaration shadows primitive" compile errors because they are now handled by stage2 AstGen. * stage1/stage2 AstGen: notice when using `@""` syntax and: - treat `_` as a regular identifier - skip checking if an identifire is a primitive Check the new test cases for clarifications on semantics. closes #6062
2021-08-24stage1: remove incorrect compile error for var redeclarationAndrew Kelley
Locals are not allowed to shadow declarations, but declarations are allowed to shadow each other, as long as there are no ambiguous references. closes #678
2021-08-23stage1: `@intToEnum` implicitly does an `@intCast`Andrew Kelley
This is a backwards-compatible language change. Previously, `@intToEnum` coerced its integer operand to the integer tag type of the destination enum type, often requiring the callsite to additionally wrap the operand in an `@intCast`. Now, the `@intCast` is implicit, and any integer operand can be passed to `@intToEnum`. The same as before, it is illegal behavior to pass any integer which does not have a corresponding enum tag.
2021-07-11stage2 astgen: error for return outside of function scopeJacob G-W
2021-07-02stage2: improve AstGen FileNotFound error messageAndrew Kelley
Partially addresses #9203. It fixes the first case, but not the second one mentioned in the issue.
2021-07-02compile errors test harness: support unknown file/line/columnAndrew Kelley
This gets us 2 more passing compile error test cases.
2021-07-02tokenizer: clean up invalid token errorAndrew Kelley
It now displays the byte with proper printability handling. This makes the relevant compile error test case no longer a regression in quality from stage1 to stage2.
2021-07-02AstGen: cleanups to pass more compile error test casesAndrew Kelley
2021-07-02AstGen: pass more compile error testsAndrew Kelley
* Implement "initializing array with struct syntax" * Implement "'_' used as an identifier without @\"_\" syntax" * Fix source location of "missing parameter name" * Update test cases where appropriate
2021-07-02stage2: improve compile errors from tokenizerAndrew Kelley
In order to not regress the quality of compile errors, some improvements had to be made. * std.zig.parseCharLiteral is improved to return more detailed parse failure information. * tokenizer is improved to handle null bytes in the middle of strings, character literals, and line comments. * validating how many unicode escape digits in string literals is moved to std.zig.parseStringLiteral rather than handled in the tokenizer. * when a tokenizer error occurs, if the reported token is the 'invalid' tag, an error note is added to point to the invalid byte location. Further improvements would be: - Mention the expected set of allowed bytes at this location. - Display the invalid byte (if printable, print it, otherwise escape-print it).
2021-07-02avoid calling into stage1 backend when AstGen failsAndrew Kelley
The motivation for this commit is that there exists source files which produce ast-check errors, but crash stage1 or otherwise trigger stage1 bugs. Previously to this commit, Zig would run AstGen, collect the compile errors, run stage1, report stage1 compile errors and exit if any, and then report AstGen compile errors. The main change in this commit is to report AstGen errors prior to invoking stage1, and in fact if any AstGen errors occur, do not invoke stage1 at all. This caused most of the compile error tests to fail due to things such as unused local variables and mismatched stage1/stage2 error messages. It was taking a long time to update the test cases one-by-one, so I took this opportunity to unify the stage1 and stage2 testing harness, specifically with regards to compile errors. In this way we can start keeping track of which tests pass for 1, 2, or both. `zig build test-compile-errors` no longer works; it is now integrated into `zig build test-stage2`. This is one step closer to executing compile error tests in parallel; in fact the ThreadPool object is already in scope. There are some cases where the stage1 compile errors were actually better; those are left failing in this commit, to be addressed in a follow-up commit. Other changes in this commit: * build.zig: improve support for -Dstage1 used with the test step. * AstGen: minor cosmetic changes to error messages. * stage2: add -fstage1 and -fno-stage1 flags. This now allows one to download a binary of the zig compiler and use the llvm backend of self-hosted. This was also needed for hooking up the test harness. However, I realized that stage1 calls exit() and also has memory leaks, so had to complicate the test harness by not using this flag after all and instead invoking as a child process. - These CLI flags will disappear once we start shipping the self-hosted compiler as the main compiler. Until then, they can be used to try out the work-in-progress stage2. * stage2: select the LLVM backend by default for release modes, as long as the target architecture is supported by LLVM. * test harness: support setting the optimize mode
2021-07-02AstGen: introduce 'reachableExpr' functionAndrew Kelley
This function can be swapped out for calls to expr() to report a compile error when the expression results in control flow that does not return.
2021-07-02AstGen: implement compile error for useless localsAndrew Kelley
When a local variable has an initialization expression of type 'noreturn', emit a compile error. This brings this branch closer to parity with master branch.
2021-07-02move "unreachable code" error from stage1 to stage2Andrew Kelley
* AstGen: implement "unreachable code" error for blocks. This works at the statement level. * stage1: remove the "unreachable code" error implementation, which means removing the `is_gen` field from IrInstSrc. This is one small step towards a smaller memory footprint for stage1. The benefits won't be realized until a future commit because this flag took advantage of padding. There may be a regression here with "union has no associated enum" error, and there is a regression with the following code: ```zig const a = noreturn; ``` A future commit will address these regressions.
2021-06-23nice error for unsupported async sockets on WindowsJonathan Marler
2021-06-13Improve error message when std.fmt.format is missing argumentsJarred Sumner
Use fmt in fmt so the number in the error message is fmt'd
2021-06-12Renamed @byteOffsetOf to @offsetOfExonorid
2021-06-08stage1: make `@truncate` to an integer type of different sign an error at ↵Matthew Borkowski
comptime too
2021-05-28stage1: get test-compile-errors passing againAndrew Kelley
2021-05-17update langref, compile-error tests, safety testsAndrew Kelley
for the std.builtin re-arranging
2021-05-08update usage of std.testing in behavior and standalone testsVeikka Tuominen