Sema: do not immediately destroy failed generic instantiation

Closes #12535
Closes #12765
Closes #12927
This commit is contained in:
Veikka Tuominen
2022-09-30 15:44:28 +03:00
parent daeb992c73
commit abd005f302
5 changed files with 332 additions and 222 deletions

View File

@@ -0,0 +1,22 @@
const std = @import("std");
const Version = std.SemanticVersion;
const print = @import("std").debug.print;
fn readVersion() Version {
const version_file = "foo";
const len = std.mem.indexOfAny(u8, version_file, " \n") orelse version_file.len;
const version_string = version_file[0..len];
return Version.parse(version_string) catch unreachable;
}
const version: Version = readVersion();
pub export fn entry() void {
print("Version {}.{}.{}+{?s}\n", .{ version.major, version.minor, version.patch, version.build });
}
// error
// backend=llvm
// target=native
//
// :9:48: error: caught unexpected error 'InvalidVersion'
// :12:37: note: called from here

View File

@@ -0,0 +1,27 @@
fn List(comptime Head: type, comptime Tail: type) type {
return union {
const Self = @This();
head: Head,
tail: Tail,
fn AppendReturnType(comptime item: anytype) type {
return List(Head, List(@TypeOf(item), void));
}
};
}
fn makeList(item: anytype) List(@TypeOf(item), void) {
return List(@TypeOf(item), void){ .head = item };
}
pub export fn entry() void {
@TypeOf(makeList(42)).AppendReturnType(64);
}
// error
// backend=llvm
// target=native
//
// :18:43: error: value of type 'type' ignored
// :18:43: note: all non-void values must be used
// :18:43: note: this error can be suppressed by assigning the value to '_'

View File

@@ -0,0 +1,14 @@
const std = @import("std");
pub export fn entry() void {
var ohnoes: *usize = undefined;
_ = sliceAsBytes(ohnoes);
}
fn sliceAsBytes(slice: anytype) std.meta.trait.isPtrTo(.Array)(@TypeOf(slice)) {}
// error
// backend=llvm
// target=native
//
// :7:63: error: expected type 'type', found 'bool'