diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-17 17:03:52 +0300 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-07-21 12:21:30 -0700 |
| commit | 8feb3987608945040c955bd7b24be3841ebf74ac (patch) | |
| tree | 192a1ec257081c7f4771e59ee1fc3e499ae7cf6f /src/type.zig | |
| parent | d851b24180fdf2b622b06e9a35e315541fb10aa1 (diff) | |
| download | zig-8feb3987608945040c955bd7b24be3841ebf74ac.tar.gz zig-8feb3987608945040c955bd7b24be3841ebf74ac.zip | |
Sema: validate function parameter types and return type
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/type.zig b/src/type.zig index 59f0668770..bdddaab070 100644 --- a/src/type.zig +++ b/src/type.zig @@ -4643,13 +4643,27 @@ pub const Type = extern union { } /// Asserts the type is a function. - pub fn fnCallingConventionAllowsZigTypes(self: Type) bool { - return switch (self.fnCallingConvention()) { + pub fn fnCallingConventionAllowsZigTypes(cc: std.builtin.CallingConvention) bool { + return switch (cc) { .Unspecified, .Async, .Inline, .PtxKernel => true, else => false, }; } + pub fn isValidParamType(self: Type) bool { + return switch (self.zigTypeTagOrPoison() catch return true) { + .Undefined, .Null, .Opaque, .NoReturn => false, + else => true, + }; + } + + pub fn isValidReturnType(self: Type) bool { + return switch (self.zigTypeTagOrPoison() catch return true) { + .Undefined, .Null, .Opaque => false, + else => true, + }; + } + /// Asserts the type is a function. pub fn fnIsVarArgs(self: Type) bool { return switch (self.tag()) { @@ -5650,6 +5664,10 @@ pub const Type = extern union { const union_obj = ty.cast(Payload.Union).?.data; return union_obj.srcLoc(mod); }, + .@"opaque" => { + const opaque_obj = ty.cast(Payload.Opaque).?.data; + return opaque_obj.srcLoc(mod); + }, .atomic_order, .atomic_rmw_op, .calling_convention, |
