118 Commits

Author SHA1 Message Date
zooster
4055e6055b
AstGen: disallow leading zeroes in int literals and int types
This makes `0123` and `u0123` etc. illegal.

I'm now confident that this is a good change because
I actually caught two C header translation mistakes in `haiku.zig` with this.
Clearly, `0123` being octal in C (TIL) can cause confusion, and we make this easier to read by
requiring `0o` as the prefix and now also disallowing leading zeroes in integers.

For consistency and because it looks weird, we disallow it for integer types too (e.g. `u0123`).

Fixes #11963
Fixes #12417
2022-08-18 19:54:51 +03:00
Veikka Tuominen
b038dba06b
Merge pull request #12462 from Vexu/stage2-noreturn
Stage2: improve behavior of noreturn
2022-08-18 17:18:57 +03:00
Andrew Kelley
2cccd14491 fix typo in compile error message 2022-08-17 14:09:42 -07:00
Veikka Tuominen
59b6483d63 add test 2022-08-17 14:09:42 -07:00
Veikka Tuominen
233049503a Sema: allow empty enums and unions 2022-08-17 23:03:04 +03:00
Veikka Tuominen
c3d5428cba Sema: properly handle noreturn fields in unions 2022-08-17 22:07:48 +03:00
Veikka Tuominen
b0a55e1b3b Sema: make noreturn error union behave correctly 2022-08-17 20:10:18 +03:00
Veikka Tuominen
db0f372da8 Sema: make optional noreturn behave correctly 2022-08-17 20:10:18 +03:00
Veikka Tuominen
9d4561ef00 AstGen: detect declarations shadowing locals
Closes #9355
2022-08-16 20:35:03 +03:00
LeRoyce Pearson
cb901e578c
stage2: add compile errors for comptime @shrExact and @divExact failures 2022-08-15 11:28:42 +03:00
martinhath
92568a0097
Sema: add error for signed integer division
stage1 error reads

error: division with 'i32' and 'comptime_int': signed integers must use @divTrunc, @divFloor, or @divExact

Fixes: #12339
2022-08-12 11:45:11 +03:00
Andrew Kelley
e0178890ba
Merge pull request #12379 from ifreund/packed-struct-explicit-backing-int
stage2: Implement explicit backing integers for packed structs
2022-08-10 19:13:29 -04:00
InKryption
e218b7ea0c stage2: add compile error for invalid null/undefined pointer cast 2022-08-10 16:39:46 -04:00
LeRoyce Pearson
0e118ed0ac stage2: add compile error for shlExact overflow
- moves a stage1 test case and makes it target `llvm` backend instead
  of `stage1` backend
2022-08-10 16:14:30 -04:00
Isaac Freund
0d32b73078
stage2: Implement explicit backing integers for packed structs
Now the backing integer of a packed struct type may be explicitly
specified with e.g. `packed struct(u32) { ... }`.
2022-08-10 19:54:45 +02:00
Veikka Tuominen
b757a96d5c Sema: add declared here note to function call errors 2022-08-09 23:37:26 +03:00
Veikka Tuominen
0fd90749d1 stage2: generate call arguments in separate blocks 2022-08-09 16:19:55 +03:00
Veikka Tuominen
c76b5c1a31 stage2: correct node offset of nested declarations 2022-08-09 11:59:10 +03:00
Veikka Tuominen
d769fd0102 stage2: pass anon name strategy to reify 2022-08-08 18:28:39 -07:00
Andrew Kelley
11c715cd5a remove brittle test case
see #12358
2022-08-07 16:07:21 -07:00
Anton Lilja
86d9c3de2b
Sema: fix infinite recursion in explainWhyTypeIsComptime
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-08-06 14:17:09 +03:00
Veikka Tuominen
4ab60dc18b Sema: add error for dependency loops 2022-08-03 17:10:39 +03:00
Veikka Tuominen
b79929b2ea AstGen: better source location for if/while condition unwrapping 2022-08-03 16:45:33 +03:00
Veikka Tuominen
d1d24b426d AstGen: check loop bodies and else branches for unused result 2022-08-03 16:45:33 +03:00
Veikka Tuominen
aa78ebaf95 Sema: improve circular dependency errors 2022-08-03 16:45:33 +03:00
Veikka Tuominen
02112f8836 AstGen: add error for break/continue out of defer expression 2022-08-03 16:45:33 +03:00
Veikka Tuominen
6547c3887e Sema: add error for closure capture at runtime 2022-08-03 16:45:33 +03:00
Veikka Tuominen
14f0b70570 Sema: add safety for sentinel slice 2022-08-02 18:34:30 +03:00
Veikka Tuominen
e47706f344 Sema: validate packed struct field types 2022-08-01 23:59:40 +03:00
Veikka Tuominen
f1768b40b2 stage2: better source location for var decls 2022-08-01 23:37:01 +03:00
Veikka Tuominen
57f9405a8f Sema: validate bitcast operand type 2022-08-01 23:37:01 +03:00
Veikka Tuominen
02dc073260 Sema: check comptime slice sentinel 2022-07-30 11:07:37 +03:00
Veikka Tuominen
4758752e5d Sema: implement coercion from tuples to tuples
Closes #12242
2022-07-30 00:18:08 +03:00
Veikka Tuominen
17622b9db1 Sema: implement @Type for functions
Closes #12280
2022-07-30 00:18:08 +03:00
Andrew Kelley
daac39364a fix compile error test case note column number 2022-07-29 02:35:06 -07:00
Veikka Tuominen
fdaf9c40d6 stage2: handle tuple init edge cases 2022-07-29 10:12:36 +03:00
Veikka Tuominen
9e0a930ce3 stage2: add error for comptime control flow in runtime block 2022-07-29 10:08:35 +03:00
Andrew Kelley
bdaa915a02 test-cases: remove failing test
This causes a stack overflow in a debug build of stage3 unfortunately. I
will open an issue to track this test coverage, which we absolutely
should get working - users of the compiler should get a compile error,
not a segfault if they hit the default branch quota from abusing
recursive inline functions.

Note that the problem does not occur in a release build of stage3
which has significantly reduced stack usage.

On Linux, I tried bumping up the stack size from 32 MiB to 64 MiB and it
did not solve the problem. I'm not sure why not. It seems like it should
be fine.

Note that we also have a problem of running test-cases in multi-threaded
mode which is currently the default. Currently Zig threads are spawned
with 16 MiB stack space.
2022-07-26 20:12:40 -07:00
Andrew Kelley
c8c798685f
Merge pull request #12244 from Vexu/stage2
Minor stage2 fixes
2022-07-26 17:41:26 -07:00
Veikka Tuominen
d6e3988fe8 Sema: better error when coercing error sets 2022-07-26 23:29:54 +03:00
Veikka Tuominen
5d99e5ecd4 Sema: improve expression value ignored error
Closes #4483
2022-07-26 16:40:24 +03:00
Veikka Tuominen
3d18c8c130 Sema: resolve lazy values for compile log
Close #12204
2022-07-26 16:40:24 +03:00
Veikka Tuominen
d78532f462 Sema: give comptime_field_ptr priority over field_ptr in tuples
Closes #11983
2022-07-26 16:40:24 +03:00
Veikka Tuominen
a463dc7d6c AstGen: disable null bytes and empty stings in some places
Namely:
 * test names
 * identifiers
 * library names
 * import strings
2022-07-26 12:14:59 +03:00
Veikka Tuominen
825fc654b6 Sema: better source location for builtin options 2022-07-26 12:14:59 +03:00
Veikka Tuominen
28478a4bac Module: improve handling of errors in @call arguments 2022-07-26 12:14:59 +03:00
Meghan
dea437edfb
stage2: implement noinline fn 2022-07-24 11:56:33 +03:00
Andreas Reischuck
903bed931d report better error for package not found in stage2 2022-07-24 11:55:37 +03:00
Veikka Tuominen
2436dd2c1b Sema: validate duplicate fields in anon structs 2022-07-23 15:40:12 +03:00
Veikka Tuominen
5b29275240 Sema: add some more 'declared here' notes 2022-07-23 15:40:12 +03:00