From d45e348340ab1e5ed143e710e78610c42acd5f31 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 9 Feb 2023 15:05:50 +0800 Subject: [PATCH] Update vm.h --- src/vm.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vm.h b/src/vm.h index 9c3be432..a9f54b66 100644 --- a/src/vm.h +++ b/src/vm.h @@ -896,7 +896,7 @@ public: } return x; } - TypeError("unhashable type: " + OBJ_TP_NAME(obj)); + TypeError("unhashable type: " + OBJ_TP_NAME(obj).escape(true)); return 0; } @@ -927,14 +927,14 @@ public: void ZeroDivisionError(){ _error("ZeroDivisionError", "division by zero"); } void IndexError(const _Str& msg){ _error("IndexError", msg); } void ValueError(const _Str& msg){ _error("ValueError", msg); } - void NameError(const _Str& name){ _error("NameError", "name '" + name + "' is not defined"); } + void NameError(const _Str& name){ _error("NameError", "name " + name.escape(true) + " is not defined"); } void AttributeError(PyVar obj, const _Str& name){ - _error("AttributeError", "type '" + OBJ_TP_NAME(obj) + "' has no attribute '" + name + "'"); + _error("AttributeError", "type " + OBJ_TP_NAME(obj).escape(true) + " has no attribute " + name.escape(true)); } inline void check_type(const PyVar& obj, const PyVar& type){ - if(!obj->is_type(type)) TypeError("expected '" + OBJ_NAME(type) + "', but got '" + OBJ_TP_NAME(obj) + "'"); + if(!obj->is_type(type)) TypeError("expected " + OBJ_NAME(type).escape(true) + ", but got " + OBJ_TP_NAME(obj).escape(true)); } template @@ -946,7 +946,7 @@ public: } template - T& py_cast(const PyVar& obj){ + inline T& py_cast(const PyVar& obj){ check_type(obj, T::_type(this)); return OBJ_GET(T, obj); }