Commit Graph

296 Commits

Author SHA1 Message Date
Andrew Kelley
42ea2d0d1c
fix @export for arrays and allow sections on extern variables
previously `@export` for an array would panic with a TODO message.
now it will do the export. However, it uses the variable's name
rather than the name passed to `@export`. Issue #2679 remains open
for that problem.
2019-06-14 15:28:52 -04:00
SamTebbs33
6c160b8856 Add check for null body in if, for and while 2019-06-10 00:41:33 -04:00
Andrew Kelley
b735764898
different array literal syntax when inferring the size
old syntax:  []i32{1, 2, 3}
new syntax: [_]i32{1, 2, 3}

closes #1797
2019-06-09 19:26:32 -04:00
Andrew Kelley
78f32259da
default struct field initialization expressions
closes #485
2019-05-30 15:46:11 -04:00
Andrew Kelley
1ccbd1fb67
use works on unions and enums in addition to structs 2019-05-29 16:31:49 -04:00
Andrew Kelley
b66438eb80
no "use of undeclared identifer" in dead comptime branches 2019-05-28 18:19:27 -04:00
LemonBoy
528c151a55 Reject undefined as type
Make analyze_type_expr behave like ir_resolve_type when the user tries
to use `undefined` as a type.

Closes #2436
2019-05-28 18:02:57 -04:00
Andrew Kelley
269a53b6af
introduce @hasDecl builtin function
closes #1439
2019-05-26 16:21:03 -04:00
Shawn Landden
1fdb24827f
breaking changes to all bit manipulation intrinsics
* `@clz`, `@ctz`, `@popCount`, `@bswap`, `@bitreverse` now
   have a type parameter
 * rename @bitreverse to @bitReverse
 * rename @bswap to @byteSwap

Closes #2119
Closes #2120
2019-05-16 16:37:58 -04:00
Andrew Kelley
057a5d4898
slice types no longer have field access
* fix crash when doing field access of slice types. closes #2486
 * remove the deprecated Child property from slice types
 * add -Dskip-non-native build option to build script
2019-05-14 21:21:59 -04:00
LemonBoy
b05e8d46ec Change the enum value allocation strategy 2019-05-11 21:29:53 +02:00
LemonBoy
c766f3f9ca Support signed types as enum tags 2019-05-11 21:28:58 +02:00
Andrew Kelley
2933d6b848
add test case for previous commit
closes #2467
2019-05-10 16:57:37 -04:00
Michael Dusan
d065f297ab stage1: compile error for loop expr val ignored
closes #2460
2019-05-10 10:05:40 -04:00
Jimmi HC
6b10f03b4a Fixes and simplifications for stage 1 parser 2019-05-10 16:09:58 +02:00
Andrew Kelley
c459edac18
compile error for attempt to cast enum literal to error
closes #2203
2019-05-09 13:18:13 -04:00
Andrew Kelley
50bbb34594
C pointers support null
See #1967
2019-05-08 16:06:34 -04:00
Andrew Kelley
fb2acaff06
@sizeOf returns 0 for comptime types
This defines `@sizeOf` to be the runtime size of a type, which means
that it is zero for types such as comptime_int, type, and (enum
literal).

See #2209
2019-04-24 22:31:53 -04:00
kristopher tate
fae0c35195
test/compile_errors.zig: add regression test for ziglang/zig#532 ; 2019-04-07 10:37:43 +09:00
emekoi
4a64f26627 added error for implicit cast from *const T to *[1]T. credit: @kristate 2019-03-31 16:47:34 -05:00
Shawn Landden
66f13ba807 stage1: better error message when comparing against null
Closes: #2104
2019-03-28 15:54:44 -04:00
Andrew Kelley
5eaead6a56
implement allowzero pointer attribute
closes #1953

only needed for freestanding targets.

also adds safety for `@intToPtr` when the address is zero.
2019-03-25 12:55:45 -04:00
Andrew Kelley
3306e43984
add compile error test for invalid enum literal implicit cast
See #683
2019-03-24 18:51:24 -04:00
Andrew Kelley
aff7b38838
make switch expressions allow enum literal types
See #683
2019-03-24 01:15:21 -04:00
Andrew Kelley
64dddd7afe
add compile error for ignoring error
closes #772
2019-03-23 19:33:00 -04:00
Andrew Kelley
4615ed5ea0
float literals now parse using musl's 128 bit float code
fixes float literals not having 128 bit precision
2019-03-22 14:56:03 -04:00
Marc Tiehuis
a3f42a5fe1 Fix compile-error test case for large integer type 2019-03-23 00:20:03 +13:00
Andrew Kelley
15c316b0d8
add docs for assembly and fix global assembly parsing
Previously, global assembly was parsed expecting it to have
the template syntax. However global assembly has no inputs,
outputs, or clobbers, and thus does not have template syntax.
This is now fixed.

This commit also adds a compile error for using volatile
on global assembly, since it is meaningless.

closes #1515
2019-03-20 19:00:23 -04:00
Andrew Kelley
6d6195424d
add regression test for invalid multiple dereferences
closes #1042
2019-03-16 00:23:18 -04:00
Andrew Kelley
c40448eb9a
add compile error for wrong type with use
closes #1557
2019-03-16 00:18:10 -04:00
Andrew Kelley
4a5cd0b895
fix while continue block not checking for ignored expression
closes #957
2019-03-15 23:52:11 -04:00
Andrew Kelley
67b4de33d2
compile error for import outside package path
closes #2024

there's a new cli option `--main-pkg-path` which you can use to choose
a different root package directory besides the one inferred from the
root source file

and a corresponding build.zig API:
foo.setMainPkgPath(path)
2019-03-02 10:38:27 -05:00
Andrew Kelley
5f7d9c5845
@typeInfo for structs and opaque types is the bare name 2019-03-01 17:15:58 -05:00
Andrew Kelley
582fdc2869
fix dependency loops, pub, tests, use decls, root source
* fix dependency loop detection
   - closes #679
   - closes #1500
 * fix `pub`
 * fix tests
 * fix use decls
 * main package file gets a special "" namespace path
2019-03-01 15:35:29 -05:00
Andrew Kelley
5424b4320d
remove namespace type; files are empty structs
closes #1047
2019-02-28 10:11:32 -05:00
Andrew Kelley
763357c9c3
add test coverage for type used as switch case
closes #996
2019-02-26 19:41:36 -05:00
Andrew Kelley
d5fc826437
add test coverage for binary OR on error sets
closes #1074
2019-02-26 19:34:22 -05:00
Andrew Kelley
82fafca375 fix the libc compile error tests to only run on linux 2019-02-25 21:46:32 -05:00
Andrew Kelley
152db27146
better error message when forgetting to link against libc
closes #1698
2019-02-25 20:09:18 -05:00
Andrew Kelley
3ca861c7dd
add a compile error note when C import fails and not linking libc
closes #558
2019-02-25 19:31:30 -05:00
Andrew Kelley
52bb71867d
implement vector negation
also fix vector behavior tests, they weren't actually testing
runtime vectors, but now they are.

See #903
2019-02-22 13:28:57 -05:00
Andrew Kelley
1066004b79
better handling of arrays in packed structs
* Separate LoadPtr IR instructions into pass1 and pass2 variants.
 * Define `type_size_bits` for extern structs to be the same as
   their `@sizeOf(T) * 8` and allow them in packed structs.
 * More helpful error messages when trying to use types in
   packed structs that are not allowed.
 * Support arrays in packed structs even when they are not
   byte-aligned.
 * Add compile error for using arrays in packed structs when the
   padding bits would be problematic. This is necessary since
   we do not have packed arrays.

closes #677
2019-02-21 14:44:14 -05:00
Andrew Kelley
3ee9d06cbd
packed structs support comptime bitcasting
* `type_size_store` is no longer a thing. loading and storing a pointer
   to a value may dereference up to `@sizeOf(T)` bytes, even for
   integers such as `u24`.
 * fix `types_have_same_zig_comptime_repr` to not think that the
   same `ZigTypeId` means the `ConstExprValue` neccesarily has the
   same representation.
 * implement `buf_write_value_bytes` and `buf_read_value_bytes` for
   `ContainerLayoutPacked`

closes #1120
2019-02-20 22:40:41 -05:00
Andrew Kelley
079728752e
deduplicate compile errors for undeclared identifiers
closes #111
2019-02-20 08:04:46 -05:00
Andrew Kelley
1034af40f9
Merge branch 'slice-deref-failure' of https://github.com/matthew-mcallister/zig into matthew-mcallister-slice-deref-failure 2019-02-19 15:27:10 -05:00
LemonBoy
400006bbe7 Prevent crash in tagged enums rendering (#1986)
* Prevent crash in tagged enums rendering

* Add a test case
2019-02-19 15:18:57 -05:00
Andrew Kelley
ea3d9d5c53
add test for 74bdc1d1f8 2019-02-18 18:11:30 -05:00
Matthew McAllister
c70ee9177e Check for duped error messages in compile tests 2019-02-17 15:33:28 -08:00
Matthew McAllister
51783510b9 Deduplicate compile log statement warnings 2019-02-17 14:02:37 -08:00
Matthew McAllister
91989e70ba Fix lvalue dereference type checking
Previously, if a dereference instruction was an lvalue, it would fail to
typecheck that the value being dereferenced was indeed a pointer.
Although a little clunky, this change obviates the need for redundant
type checks scattered about the analysis.
2019-02-16 17:37:47 -08:00