diff --git a/src/Obj.cc b/src/Obj.cc index 9c3b50a950..fdf2b7ef99 100644 --- a/src/Obj.cc +++ b/src/Obj.cc @@ -100,21 +100,21 @@ BroObj::~BroObj() delete location; } -void BroObj::Warn(const char* msg, const BroObj* obj2, int pinpoint_only) const +void BroObj::Warn(const char* msg, const BroObj* obj2, int pinpoint_only, const Location* expr_location) const { ODesc d; - DoMsg(&d, msg, obj2, pinpoint_only); + DoMsg(&d, msg, obj2, pinpoint_only, expr_location); reporter->Warning("%s", d.Description()); reporter->PopLocation(); } -void BroObj::Error(const char* msg, const BroObj* obj2, int pinpoint_only) const +void BroObj::Error(const char* msg, const BroObj* obj2, int pinpoint_only, const Location* expr_location) const { if ( suppress_errors ) return; ODesc d; - DoMsg(&d, msg, obj2, pinpoint_only); + DoMsg(&d, msg, obj2, pinpoint_only, expr_location); reporter->Error("%s", d.Description()); reporter->PopLocation(); } @@ -200,7 +200,7 @@ void BroObj::UpdateLocationEndInfo(const Location& end) } void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2, - int pinpoint_only) const + int pinpoint_only, const Location* expr_location) const { d->SetShort(); @@ -211,6 +211,8 @@ void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2, if ( obj2 && obj2->GetLocationInfo() != &no_location && *obj2->GetLocationInfo() != *GetLocationInfo() ) loc2 = obj2->GetLocationInfo(); + else if ( expr_location ) + loc2 = expr_location; reporter->PushLocation(GetLocationInfo(), loc2); } diff --git a/src/Obj.h b/src/Obj.h index 047eec0856..21730ff367 100644 --- a/src/Obj.h +++ b/src/Obj.h @@ -118,9 +118,9 @@ public: // included in the message, though if pinpoint_only is non-zero, // then obj2 is only used to pinpoint the location. void Warn(const char* msg, const BroObj* obj2 = 0, - int pinpoint_only = 0) const; + int pinpoint_only = 0, const Location* expr_location = 0) const; void Error(const char* msg, const BroObj* obj2 = 0, - int pinpoint_only = 0) const; + int pinpoint_only = 0, const Location* expr_location = 0) const; // Report internal errors. void BadTag(const char* msg, const char* t1 = 0, @@ -178,7 +178,7 @@ private: friend class SuppressErrors; void DoMsg(ODesc* d, const char s1[], const BroObj* obj2 = 0, - int pinpoint_only = 0) const; + int pinpoint_only = 0, const Location* expr_location = 0) const; void PinPoint(ODesc* d, const BroObj* obj2 = 0, int pinpoint_only = 0) const; diff --git a/src/Val.cc b/src/Val.cc index 50c36d7239..d989bce461 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -3556,7 +3556,7 @@ bool OpaqueVal::DoUnserialize(UnserialInfo* info) return true; } -Val* check_and_promote(Val* v, const BroType* t, int is_init) +Val* check_and_promote(Val* v, const BroType* t, int is_init, const Location* expr_location) { if ( ! v ) return 0; @@ -3580,7 +3580,7 @@ Val* check_and_promote(Val* v, const BroType* t, int is_init) if ( same_type(t, vt, is_init) ) return v; - t->Error("type clash", v); + t->Error("type clash", v, 0, expr_location); Unref(v); return 0; } @@ -3589,9 +3589,9 @@ Val* check_and_promote(Val* v, const BroType* t, int is_init) (! IsArithmetic(v_tag) || t_tag != TYPE_TIME || ! v->IsZero()) ) { if ( t_tag == TYPE_LIST || v_tag == TYPE_LIST ) - t->Error("list mixed with scalar", v); + t->Error("list mixed with scalar", v, 0, expr_location); else - t->Error("arithmetic mixed with non-arithmetic", v); + t->Error("arithmetic mixed with non-arithmetic", v, 0, expr_location); Unref(v); return 0; } @@ -3604,7 +3604,7 @@ Val* check_and_promote(Val* v, const BroType* t, int is_init) TypeTag mt = max_type(t_tag, v_tag); if ( mt != t_tag ) { - t->Error("over-promotion of arithmetic value", v); + t->Error("over-promotion of arithmetic value", v, 0, expr_location); Unref(v); return 0; } diff --git a/src/Val.h b/src/Val.h index c253c265db..c854d2b015 100644 --- a/src/Val.h +++ b/src/Val.h @@ -1219,7 +1219,7 @@ protected: // Unref()'ing the original. If not a match, generates an error message // and returns nil, also Unref()'ing v. If is_init is true, then // the checking is done in the context of an initialization. -extern Val* check_and_promote(Val* v, const BroType* t, int is_init); +extern Val* check_and_promote(Val* v, const BroType* t, int is_init, const Location* expr_location = nullptr); // Given a pointer to where a Val's core (i.e., its BRO value) resides, // returns a corresponding newly-created or Ref()'d Val. ptr must already