Commit Graph

689 Commits

Author SHA1 Message Date
Veikka Tuominen
c3b85e4e2f Sema: further enhance explanation of why expr is evaluated at comptime 2022-10-28 13:31:16 +03:00
r00ster91
51d9db8569 fix(text): hyphenate "comptime" adjectives 2022-10-05 21:19:30 +02:00
r00ster91
654e0b6679 fix(text): hyphenation and other fixes 2022-10-05 21:19:10 +02:00
John Schmidt
b6bda5183e sema: load the correct AST in failWithInvalidComptimeFieldStore
The container we want to get the fields from might not be declared in the
same file as the block we are analyzing, so we should get the AST from
the decl's file instead.
2022-09-26 08:56:34 +02:00
Veikka Tuominen
b2f02a820f Sema: check for astgen failures in semaStructFields
The struct might be a top level struct in which case it might not have Zir.

Closes #12548
2022-08-22 11:16:36 +03:00
Veikka Tuominen
e8102d8738 Sema: add note about function call being comptime because of comptime only return type 2022-08-21 12:24:48 +03:00
Veikka Tuominen
2f34d06d01 Sema: analyzeInlineCallArg needs a block for the arg and the param 2022-07-25 22:04:08 +03:00
Veikka Tuominen
1463144fc8 Compilation: point caret in error message at the main token 2022-07-15 15:11:43 +03:00
r00ster91
da75eb0d79
Compilation: indent multiline error messages properly
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-07-12 00:10:39 +03:00
Jakub Konka
62625d9d95 test: migrate stage1 compile error tests to updated test manifest 2022-04-28 18:35:01 +02:00
Andrew Kelley
243afdcdf5 test harness improvements
* `-Dskip-compile-errors` is removed; `-Dskip-stage1` is added.
 * Use `std.testing.allocator` instead of a new instance of GPA.
   - Fix the memory leaks this revealed.
 * Show the file name when it is not parsed correctly such as when the
   manifest is missing.
   - Better error messages when test files are not parsed correctly.
 * Ignore unknown files such as swap files.
 * Move logic from declarative file to the test harness implementation.
 * Move stage1 tests to stage2 tests where appropriate.
2022-03-31 15:10:31 -07:00
Andrew Kelley
47dfaf47b8 stage2: test compile errors independently
Until we land some incremental compilation bug fixes, this prevents CI
failures when running the compile errors test cases.
2022-03-30 11:22:27 -07:00
Andrew Kelley
9aa431cba3 test harness: include case names for compile errors
in the progress nodes
2022-03-29 12:01:45 -07:00
Cody Tapscott
0568b45779 Move existing compile errors to independent files
Some cases had to stay behind, either because they required complex case
configuration that we don't support in independent files yet, or because
they have associated comments which we don't want to lose track of.

To make sure I didn't drop any tests in the process, I logged all
obj/test/exe test cases from a run of "zig build test" and compared
before/after this change.

All of the test cases match, with two exceptions:
 - "use of comptime-known undefined function value" was deleted, since
   it was a duplicate
 - "slice sentinel mismatch" was renamed to "vector index out of
   bounds", since it was incorrectly named
2022-03-25 12:27:46 -07:00
Cody Tapscott
7f64f7c925 Add rudimentary compile error test file support
This brings two quality-of-life improvements for folks working on
compile error test cases:
 - test cases can be added/changed without re-building Zig
 - wrapping the source in a multi-line string literal is not necessary

I decided to keep things as simple as possible for this initial
implementation. The test "manifest" is a contiguous comment block at the
end of the test file:
1. The first line is the test case name
2. The second line is a blank comment
2. The following lines are expected errors

Here's an example:
```zig
const U = union(enum(u2)) {
    A: u8,
    B: u8,
    C: u8,
    D: u8,
    E: u8,
};
export fn entry() void {
    _ = U{ .E = 1 };
}

// union with too small explicit unsigned tag type
//
// tmp.zig:1:22: error: specified integer tag type cannot represent every field
// tmp.zig:1:22: note: type u2 cannot fit values in range 0...4
```

The mode of the test (obj/exe/test), as well as the target
(stage1/stage2) is determined based on the directory containing the
test.

We'll probably eventually want to support embedding this information
in the test files themselves, similar to the arocc test runner, but
that enhancement can be tackled later.
2022-03-25 12:25:43 -07:00
Mitchell Hashimoto
a36f4ee290 stage2: able to slice to sentinel index at comptime
The runtime behavior allowed this in both stage1 and stage2, but stage1
fails with index out of bounds during comptime. This behavior makes
sense to support, and comptime behavior should match runtime behavior. I
implement this fix only in stage2.
2022-03-23 17:08:08 -04:00
Mitchell Hashimoto
91fd0f42c8 stage2: out of bounds error for slicing 2022-03-21 22:10:34 -04:00
Daniel Hooper
911c839e97
add error when binary ops don't have matching whitespace on both sides
This change also moves the warning about "&&" from the AstGen into the parser so that the "&&" warning can supersede the whitespace warning.
2022-03-20 12:55:04 +02:00
Robin Voetter
5c3325588e stage1: make type names more unique 2022-03-19 19:40:46 -04:00
Mitchell Hashimoto
394252c9db stage2: move duplicate error set check to AstGen 2022-03-16 01:41:22 -04:00
Jonathan Marler
d805adddd6 deprecated TypeInfo in favor of Type
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-03-08 20:38:12 +02:00
Veikka Tuominen
f8154905e7 stage1: rename TypeInfo.FnArg to Fn.Param 2022-02-23 09:44:36 +02:00
Veikka Tuominen
2f0204aca3 parser: fix "previous field here" pointing to wrong field 2022-02-19 10:15:54 +02:00
Veikka Tuominen
6b65590715 parser: add notes to decl_between_fields error 2022-02-17 22:16:26 +02:00
Veikka Tuominen
92f2767814 parser: add error for missing colon before continue expr
If a '(' is found where the continue expression was expected and it is
on the same line as the previous token issue an error about missing
colon before the continue expression.
2022-02-17 20:51:26 +02:00
Veikka Tuominen
c9dde10f86 stage1: improve error message when casting tuples 2022-02-17 17:39:54 +02:00
Veikka Tuominen
9c36cf92f0 parser: make some errors point to end of previous token
For some errors if the found token is not on the same line as
the previous token, point to the end of the previous token.
This usually results in more helpful errors.
2022-02-17 14:23:35 +02:00
Veikka Tuominen
8a432436ae update compile error tests 2022-02-13 13:48:20 +02:00
Sebsatian Keller
f5471299d8
stage 1: improve error message if error union is cast to payload (#10770)
Also: Added special error message for for `?T` to `T` casting
2022-02-09 20:35:53 -05:00
Andrew Kelley
449554a730 stage2: remove anytype fields from the language
closes #10705
2022-02-01 19:06:40 -07:00
Andrew Kelley
f4a249325e stage1: avoid anytype fields for type info
prerequisite for #10705
2022-02-01 18:10:19 -07:00
Andrew Kelley
4d22fa5a2a update behavior tests and compile error tests 2022-01-31 22:33:49 -07:00
Andrew Kelley
664e1a892c stage1: remove the "referenced here" error note
It's generally noise. The parts where it is useful will need to be
redone to not be annoying for the general case.
2022-01-20 13:27:52 -05:00
Andrew Kelley
70894d5c2f AstGen: fix loop result locations
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-27 15:30:31 -07:00
Isaac Freund
9f9f215305
stage1, stage2: rename c_void to anyopaque (#10316)
zig fmt now replaces c_void with anyopaque to make updating
code easy.
2021-12-19 00:24:45 -05:00
Andrew Kelley
8031783539 stage1: fix regression of shift by negative value error
The previous commit (38b2d62092) 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-08 19:09:37 -07:00
Matthew Borkowski
c98b020ce2 parse.zig: make chained comparison operators a parse error 2021-12-02 11:59:29 -08:00
Lee Cannon
80bbf234e0
allocgate: fix failing tests 2021-11-30 23:32:48 +00:00
Lee Cannon
75548b50ff
allocgate: stage 1 and 2 building 2021-11-30 23:32:47 +00:00
Andrew Kelley
d3426ce634 AstGen: require binary operations to have reachable operands 2021-11-29 13:21:36 -07:00
Andrew Kelley
17f057c556 stage2: implement @typeName
* 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-27 00:27:52 -07:00
Andrew Kelley
67b201982b stage1: fix exporting enums
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-25 18:20:39 -07:00
Andrew Kelley
e266ede6e3 stage2: fix cleanup code for @import errors
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-24 19:10:58 -07:00
Andrew Kelley
02b8d88153 stage2: add test coverage for @embedFile outside package path
closes #6662
2021-11-24 14:57:13 -07:00
Andrew Kelley
c42763f8cc AstGen: use reachableExpr for return operand
Related: #9630
2021-11-24 14:47:33 -07:00
Kirk Scheibelhut
065f40a3c5 stage1: improve packed struct array padding error message 2021-11-22 21:33:08 -05:00
travisstaloch
16ac034a32
Sat shl neg rhs (#9949)
* 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-15 13:56:27 -04:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Andrew Kelley
51a40f9a66 saturating arithmetic supports integers only 2021-09-28 20:27:28 -07:00
Josh Soref
664941bf14
Spelling corrections (#9833)
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2021-09-24 13:39:20 -04:00