mirror of https://github.com/exaloop/codon.git
parent
6dd6f47461
commit
574c74188b
|
@ -106,6 +106,7 @@ enum Error {
|
|||
SLICE_STEP_ZERO,
|
||||
OP_NO_MAGIC,
|
||||
INST_CALLABLE_STATIC,
|
||||
CATCH_EXCEPTION_TYPE,
|
||||
TYPE_CANNOT_REALIZE_ATTR,
|
||||
TYPE_UNIFY,
|
||||
TYPE_FAILED,
|
||||
|
@ -426,6 +427,8 @@ template <class... TA> std::string Emsg(Error e, const TA &...args) {
|
|||
return fmt::format("unsupported operand type(s) for {}: '{}' and '{}'", args...);
|
||||
case Error::INST_CALLABLE_STATIC:
|
||||
return fmt::format("Callable cannot take static types");
|
||||
case Error::CATCH_EXCEPTION_TYPE:
|
||||
return fmt::format("'{}' does not inherit from BaseException", args...);
|
||||
|
||||
case Error::TYPE_CANNOT_REALIZE_ATTR:
|
||||
return fmt::format("type of attribute '{}' of object '{}' cannot be inferred",
|
||||
|
|
|
@ -11,6 +11,7 @@ namespace codon::ast {
|
|||
|
||||
using namespace types;
|
||||
using namespace matcher;
|
||||
using namespace error;
|
||||
|
||||
/// Transform asserts.
|
||||
/// @example
|
||||
|
@ -119,6 +120,16 @@ void TypecheckVisitor::visit(TryStmt *stmt) {
|
|||
} else {
|
||||
// Handle all other exceptions
|
||||
c->exc = transformType(c->getException());
|
||||
|
||||
auto t = extractClassType(c->exc);
|
||||
bool exceptionOK = false;
|
||||
for (auto &p : getSuperTypes(t))
|
||||
if (p->is("std.internal.types.error.BaseException.0")) {
|
||||
exceptionOK = true;
|
||||
break;
|
||||
}
|
||||
if (!exceptionOK)
|
||||
E(Error::CATCH_EXCEPTION_TYPE, c->exc, t->toString());
|
||||
if (val)
|
||||
unify(val->getType(), extractType(c->getException()));
|
||||
ctx->blockLevel++;
|
||||
|
|
|
@ -3,3 +3,5 @@
|
|||
__all__ = ["jit", "convert", "JITError"]
|
||||
|
||||
from .decorator import jit, convert, execute, JITError
|
||||
|
||||
__codon__ = False
|
||||
|
|
|
@ -417,3 +417,5 @@ class ProxyFunc:
|
|||
data: Ptr[byte]
|
||||
T: type
|
||||
TR: type
|
||||
|
||||
__codon__: Static[bool] = True
|
||||
|
|
|
@ -569,3 +569,11 @@ def foo(x, y):
|
|||
return a
|
||||
return a
|
||||
print foo(5, (1, 2, 3)) #: 40
|
||||
|
||||
#%% nontype_name,barebones
|
||||
class Foo:
|
||||
def goo(self):
|
||||
print(self.__name__)
|
||||
Foo().goo()
|
||||
#! error: 'Foo' object has no attribute '__name__'
|
||||
#! during the realization
|
||||
|
|
Loading…
Reference in New Issue