diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-12-31 16:28:08 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-31 16:28:08 -0800 |
| commit | 93bb1d93cd18e739410009e7c77048d151a93b10 (patch) | |
| tree | 67b36291211919b9751785eecf8858195bce42d6 /src/Module.zig | |
| parent | 6c2e0c2046a4c1d01587cc15ea2f59af32743eb4 (diff) | |
| parent | 982acc22fd8674a9efbe1e65e037c464ba610882 (diff) | |
| download | zig-93bb1d93cd18e739410009e7c77048d151a93b10.tar.gz zig-93bb1d93cd18e739410009e7c77048d151a93b10.zip | |
Merge pull request #7616 from ziglang/stage2-inferred-vars
stage2: inferred local variables
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/Module.zig b/src/Module.zig index ca0718c3d5..5ea78d06d1 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -3189,7 +3189,14 @@ pub fn floatSub( } } -pub fn simplePtrType(self: *Module, scope: *Scope, src: usize, elem_ty: Type, mutable: bool, size: std.builtin.TypeInfo.Pointer.Size) Allocator.Error!Type { +pub fn simplePtrType( + self: *Module, + scope: *Scope, + src: usize, + elem_ty: Type, + mutable: bool, + size: std.builtin.TypeInfo.Pointer.Size, +) Allocator.Error!Type { if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) { return Type.initTag(.const_slice_u8); } @@ -3414,3 +3421,9 @@ pub fn getTarget(self: Module) Target { pub fn optimizeMode(self: Module) std.builtin.Mode { return self.comp.bin_file.options.optimize_mode; } + +pub fn validateVarType(mod: *Module, scope: *Scope, src: usize, ty: Type) !void { + if (!ty.isValidVarType(false)) { + return mod.fail(scope, src, "variable of type '{}' must be const or comptime", .{ty}); + } +} |
