From 17e3b88b541ed7f45d575f0f9caaa808cd0a6619 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 1 Jun 2022 17:37:07 -0700 Subject: New language feature: basic error handling. (#2253) * New language feature: basic error handling. * Fix. * Fix `tryCall` encoding according to code review. Co-authored-by: Yong He --- source/slang/slang-ast-type.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ast-type.cpp') diff --git a/source/slang/slang-ast-type.cpp b/source/slang/slang-ast-type.cpp index b6bc1f170..bcaf8f5a9 100644 --- a/source/slang/slang-ast-type.cpp +++ b/source/slang/slang-ast-type.cpp @@ -549,6 +549,11 @@ void FuncType::_toTextOverride(StringBuilder& out) out << getParamType(pp); } out << toSlice(") -> ") << getResultType(); + + if (!getErrorType()->equals(getASTBuilder()->getVoidType())) + { + out << " throws " << getErrorType(); + } } bool FuncType::_equalsImplOverride(Type * type) @@ -571,6 +576,9 @@ bool FuncType::_equalsImplOverride(Type * type) if (!resultType->equals(funcType->resultType)) return false; + if (!errorType->equals(funcType->errorType)) + return false; + // TODO: if we ever introduce other kinds // of qualification on function types, we'd // want to consider it here. @@ -586,6 +594,9 @@ Val* FuncType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet s // result type Type* substResultType = as(resultType->substituteImpl(astBuilder, subst, &diff)); + // error type + Type* substErrorType = as(errorType->substituteImpl(astBuilder, subst, &diff)); + // parameter types List substParamTypes; for (auto pp : paramTypes) @@ -601,6 +612,7 @@ Val* FuncType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet s FuncType* substType = astBuilder->create(); substType->resultType = substResultType; substType->paramTypes = substParamTypes; + substType->errorType = substErrorType; return substType; } @@ -608,6 +620,7 @@ Type* FuncType::_createCanonicalTypeOverride() { // result type Type* canResultType = resultType->getCanonicalType(); + Type* canErrorType = errorType->getCanonicalType(); // parameter types List canParamTypes; @@ -619,7 +632,7 @@ Type* FuncType::_createCanonicalTypeOverride() FuncType* canType = getASTBuilder()->create(); canType->resultType = canResultType; canType->paramTypes = canParamTypes; - + canType->errorType = canErrorType; return canType; } @@ -634,6 +647,7 @@ HashCode FuncType::_getHashCodeOverride() hashCode, getParamType(pp)->getHashCode()); } + combineHash(hashCode, getErrorType()->getHashCode()); return hashCode; } -- cgit v1.2.3