better error messages on field access
This commit is contained in:
parent
9cde2495b2
commit
3c7e9e13ce
@ -441,7 +441,7 @@ pub fn interpret(
|
|||||||
// Logic to find identifiers in accessible scopes
|
// Logic to find identifiers in accessible scopes
|
||||||
if (interpreter.huntItDown(namespace, identifier, options)) |decl_index| {
|
if (interpreter.huntItDown(namespace, identifier, options)) |decl_index| {
|
||||||
const decl = interpreter.ip.getDecl(decl_index);
|
const decl = interpreter.ip.getDecl(decl_index);
|
||||||
if(decl.ty == .none) return InterpretResult{ .nothing = {} };
|
if (decl.ty == .none) return InterpretResult{ .nothing = {} };
|
||||||
return InterpretResult{ .value = Value{
|
return InterpretResult{ .value = Value{
|
||||||
.interpreter = interpreter,
|
.interpreter = interpreter,
|
||||||
.node_idx = node_idx,
|
.node_idx = node_idx,
|
||||||
@ -613,21 +613,24 @@ pub fn interpret(
|
|||||||
else => false,
|
else => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const accessed_ty = if (inner_lhs == .simple and inner_lhs.simple == .type) irv.val else irv.ty;
|
||||||
|
if (accessed_ty != .none) {
|
||||||
if (can_have_fields) {
|
if (can_have_fields) {
|
||||||
try interpreter.recordError(
|
try interpreter.recordError(
|
||||||
node_idx,
|
node_idx,
|
||||||
"undeclared_identifier",
|
"undeclared_identifier",
|
||||||
"`{}` has no member '{s}'",
|
"`{}` has no member '{s}'",
|
||||||
.{ irv.ty.fmtType(interpreter.ip), field_name },
|
.{ accessed_ty.fmtType(interpreter.ip), field_name },
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
try interpreter.recordError(
|
try interpreter.recordError(
|
||||||
node_idx,
|
node_idx,
|
||||||
"invalid_field_access",
|
"invalid_field_access",
|
||||||
"`{}` does not support field access",
|
"`{}` does not support field access",
|
||||||
.{irv.ty.fmtType(interpreter.ip)},
|
.{accessed_ty.fmtType(interpreter.ip)},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return error.InvalidOperation;
|
return error.InvalidOperation;
|
||||||
},
|
},
|
||||||
.grouped_expression => {
|
.grouped_expression => {
|
||||||
|
@ -2677,9 +2677,9 @@ fn optionalPtrTy(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// will panic in debug mode or in tests else will return `value`
|
/// will panic in during testing else will return `value`
|
||||||
inline fn panicOrElse(message: []const u8, value: anytype) @TypeOf(value) {
|
inline fn panicOrElse(message: []const u8, value: anytype) @TypeOf(value) {
|
||||||
if (builtin.is_test or builtin.mode == .Debug) {
|
if (builtin.is_test) {
|
||||||
@panic(message);
|
@panic(message);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
|
Loading…
Reference in New Issue
Block a user