Zcu.Decl: replace typedValue with valueOrFail

Now that the legacy `Value` representation is eliminated, we can begin
to phase out the redundant `TypedValue` type.
This commit is contained in:
mlugg
2024-03-26 04:19:50 +00:00
parent 920f2c7794
commit 0d8c7ae007
3 changed files with 18 additions and 28 deletions

View File

@@ -480,17 +480,11 @@ pub const Decl = struct {
return decl.val.typeOf(zcu);
}
pub fn typedValue(decl: Decl, zcu: *const Zcu) error{AnalysisFail}!TypedValue {
/// Small wrapper for Sema to use over direct access to the `val` field.
/// If the value is not populated, instead returns `error.AnalysisFail`.
pub fn valueOrFail(decl: Decl) error{AnalysisFail}!Value {
if (!decl.has_tv) return error.AnalysisFail;
return .{
.ty = decl.typeOf(zcu),
.val = decl.val,
};
}
pub fn isFunction(decl: Decl, zcu: *const Zcu) !bool {
const tv = try decl.typedValue(zcu);
return tv.ty.zigTypeTag(zcu) == .Fn;
return decl.val;
}
/// If the Decl owns its value and it is a struct, return it,