summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-type.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-08-22 14:17:56 -0700
committerGitHub <noreply@github.com>2022-08-22 14:17:56 -0700
commit4bd3e6e02324f913e8927fe69d32c0aafe9fc831 (patch)
tree1f6ff8449feb49d00dee2bc527f7dc531a07c196 /source/slang/slang-check-type.cpp
parent393185196ed65a9eeaf9502edbf3dcce87337d81 (diff)
Make Optional<PointerType> lower to PointerType instead of a struct. (#2373)
Diffstat (limited to 'source/slang/slang-check-type.cpp')
-rw-r--r--source/slang/slang-check-type.cpp36
1 files changed, 28 insertions, 8 deletions
diff --git a/source/slang/slang-check-type.cpp b/source/slang/slang-check-type.cpp
index aa2c69126..c59e1b308 100644
--- a/source/slang/slang-check-type.cpp
+++ b/source/slang/slang-check-type.cpp
@@ -187,15 +187,27 @@ namespace Slang
return DeclRefType::create(m_astBuilder, innerDeclRef);
}
+ bool isManagedType(Type* type)
+ {
+ if (auto declRefValueType = as<DeclRefType>(type))
+ {
+ if (as<ClassDecl>(declRefValueType->declRef.getDecl()))
+ return true;
+ if (as<InterfaceDecl>(declRefValueType->declRef.getDecl()))
+ return true;
+ }
+ return false;
+ }
+
bool SemanticsVisitor::CoerceToProperTypeImpl(
TypeExp const& typeExp,
Type** outProperType,
DiagnosticSink* diagSink)
{
+ Type* result = nullptr;
Type* type = typeExp.type;
auto originalExpr = typeExp.exp;
auto expr = originalExpr;
-
if(!type && expr)
{
expr = maybeResolveOverloadedExpr(expr, LookupMask::type, diagSink);
@@ -289,18 +301,26 @@ namespace Slang
// ignore non-parameter members
}
}
- if (outProperType)
- {
- *outProperType = InstantiateGenericType(genericDeclRef, args);
- }
- return true;
+ result = InstantiateGenericType(genericDeclRef, args);
}
// default case: we expect this to already be a proper type
- if (outProperType)
+ if (!result)
+ {
+ result = type;
+ }
+
+ // Check for invalid types.
+ // We don't allow pointers to managed types.
+ if (auto ptrType = as<PtrType>(result))
{
- *outProperType = type;
+ if (isManagedType(ptrType->getValueType()))
+ {
+ getSink()->diagnose(typeExp.exp, Diagnostics::cannotDefinePtrTypeToManagedResource);
+ }
}
+
+ *outProperType = result;
return true;
}