summaryrefslogtreecommitdiff
path: root/source/slang/slang-ast-type.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-06-01 17:37:07 -0700
committerGitHub <noreply@github.com>2022-06-01 17:37:07 -0700
commit17e3b88b541ed7f45d575f0f9caaa808cd0a6619 (patch)
treeefacd5d4bf6381a5adf8055daa28f91ddc048a76 /source/slang/slang-ast-type.cpp
parentfa10f7dc23f8b93c0f9ef3fb5477871a20aaa974 (diff)
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 <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ast-type.cpp')
-rw-r--r--source/slang/slang-ast-type.cpp16
1 files changed, 15 insertions, 1 deletions
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<Type>(resultType->substituteImpl(astBuilder, subst, &diff));
+ // error type
+ Type* substErrorType = as<Type>(errorType->substituteImpl(astBuilder, subst, &diff));
+
// parameter types
List<Type*> substParamTypes;
for (auto pp : paramTypes)
@@ -601,6 +612,7 @@ Val* FuncType::_substituteImplOverride(ASTBuilder* astBuilder, SubstitutionSet s
FuncType* substType = astBuilder->create<FuncType>();
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<Type*> canParamTypes;
@@ -619,7 +632,7 @@ Type* FuncType::_createCanonicalTypeOverride()
FuncType* canType = getASTBuilder()->create<FuncType>();
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;
}