compiler: fix structFieldName crash for tuples
When struct types have no field names, the names are implicitly understood to be strings corresponding to the field indexes in declaration order. It used to be the case that a NullTerminatedString would be stored for each field in this case, however, now, callers must handle the possibility that there are no names stored at all. This commit introduces `legacyStructFieldName`, a function to fake the previous behavior. Probably something better could be done by reworking all the callsites of this function.
This commit is contained in:
@@ -656,6 +656,17 @@ pub const Key = union(enum) {
|
||||
pub fn isTuple(self: AnonStructType) bool {
|
||||
return self.names.len == 0;
|
||||
}
|
||||
|
||||
pub fn fieldName(
|
||||
self: AnonStructType,
|
||||
ip: *const InternPool,
|
||||
index: u32,
|
||||
) OptionalNullTerminatedString {
|
||||
if (self.names.len == 0)
|
||||
return .none;
|
||||
|
||||
return self.names.get(ip)[index].toOptional();
|
||||
}
|
||||
};
|
||||
|
||||
/// Serves two purposes:
|
||||
|
||||
Reference in New Issue
Block a user