summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-conversion.cpp8
-rw-r--r--source/slang/slang-check-decl.cpp4
-rw-r--r--source/slang/slang-check-expr.cpp32
-rw-r--r--source/slang/slang-check-impl.h7
-rw-r--r--source/slang/slang-check-modifier.cpp2
-rw-r--r--source/slang/slang-check-overload.cpp2
6 files changed, 40 insertions, 15 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index 0a0990ede..8b60b2725 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -488,6 +488,14 @@ namespace Slang
// then we should start by trying to resolve the ambiguous reference
// based on prioritization of the different candidates.
//
+ // TODO: A more powerful model would be to try to coerce each
+ // of the constituent overload candidates, filtering down to
+ // those that are coercible, and then disambiguating the result.
+ // Such an approach would let us disambiguate between overloaded
+ // symbols based on their type (e.g., by casting the name of
+ // an overloaded function to the type of the overload we mean
+ // to reference).
+ //
if( auto fromOverloadedExpr = as<OverloadedExpr>(fromExpr) )
{
auto resolvedExpr = maybeResolveOverloadedExpr(fromOverloadedExpr, LookupMask::Default, nullptr);
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 4ea8aa7f6..f9a514d23 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -3152,7 +3152,7 @@ namespace Slang
// that represents the explicit tag for this case.
if(auto initExpr = decl->tagExpr)
{
- initExpr = CheckExpr(initExpr);
+ initExpr = CheckTerm(initExpr);
initExpr = coerce(tagType, initExpr);
// We want to enforce that this is an integer constant
@@ -3919,7 +3919,7 @@ namespace Slang
// We must check the expression and coerce it to the
// actual type of the parameter.
//
- initExpr = CheckExpr(initExpr);
+ initExpr = CheckTerm(initExpr);
initExpr = coerce(typeExpr.type, initExpr);
paramDecl->initExpr = initExpr;
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index 0cc3a55c5..0de7acae2 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -988,7 +988,7 @@ namespace Slang
Expr* indexExpr = subscriptExpr->indexExpression;
if (indexExpr)
{
- indexExpr = CheckExpr(indexExpr);
+ indexExpr = CheckTerm(indexExpr);
}
subscriptExpr->baseExpression = baseExpr;
@@ -1167,17 +1167,27 @@ namespace Slang
{
expr->left = CheckExpr(expr->left);
expr->right = CheckTerm(expr->right);
+
return checkAssignWithCheckedOperands(expr);
}
- Expr* SemanticsVisitor::CheckExpr(Expr* expr)
+ Expr* SemanticsVisitor::CheckExpr(Expr* uncheckedExpr)
{
- auto term = CheckTerm(expr);
+ auto checkedTerm = CheckTerm(uncheckedExpr);
+
+ // First, we want to do any disambiguation that is needed in order
+ // to turn the `term` into an expression that names a single
+ // value (and not something overloaded).
+ //
+ auto checkedExpr = maybeResolveOverloadedExpr(checkedTerm, LookupMask::Default, getSink());
- // TODO(tfoley): Need a step here to ensure that the term actually
- // resolves to a (single) expression with a real type.
+ // Next, we want to ensure that the `expr` actually has a type
+ // that is allowable in an expression context (e.g., make sure
+ // that `expr` names a value and not a type).
+ //
+ // TODO: Implement this step.
- return term;
+ return checkedExpr;
}
Expr* SemanticsVisitor::CheckInvokeExprWithCheckedOperands(InvokeExpr *expr)
@@ -1255,11 +1265,11 @@ namespace Slang
Expr* SemanticsExprVisitor::visitInvokeExpr(InvokeExpr *expr)
{
// check the base expression first
- expr->functionExpr = CheckExpr(expr->functionExpr);
+ expr->functionExpr = CheckTerm(expr->functionExpr);
// Next check the argument expressions
for (auto & arg : expr->arguments)
{
- arg = CheckExpr(arg);
+ arg = CheckTerm(arg);
}
return CheckInvokeExprWithCheckedOperands(expr);
@@ -1306,7 +1316,7 @@ namespace Slang
// Next check the argument expression (there should be only one)
for (auto & arg : expr->arguments)
{
- arg = CheckExpr(arg);
+ arg = CheckTerm(arg);
}
// LEGACY FEATURE: As a backwards-compatibility feature
@@ -1822,7 +1832,7 @@ namespace Slang
Expr* SemanticsExprVisitor::visitStaticMemberExpr(StaticMemberExpr* expr)
{
- expr->baseExpression = CheckExpr(expr->baseExpression);
+ expr->baseExpression = CheckTerm(expr->baseExpression);
// Not sure this is needed -> but guess someone could do
expr->baseExpression = MaybeDereference(expr->baseExpression);
@@ -1855,7 +1865,7 @@ namespace Slang
{
auto baseExpr = inBaseExpr;
- baseExpr = CheckExpr(baseExpr);
+ baseExpr = CheckTerm(baseExpr);
baseExpr = MaybeDereference(baseExpr);
diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h
index cdd319408..a9f861d3d 100644
--- a/source/slang/slang-check-impl.h
+++ b/source/slang/slang-check-impl.h
@@ -1191,6 +1191,13 @@ namespace Slang
else
return getArg(index)->type.type;
}
+ Type* getArgTypeForInference(Index index, SemanticsVisitor* semantics)
+ {
+ if(argTypes)
+ return argTypes[index];
+ else
+ return semantics->maybeResolveOverloadedExpr(getArg(index), LookupMask::Default, nullptr)->type;
+ }
bool disallowNestedConversions = false;
diff --git a/source/slang/slang-check-modifier.cpp b/source/slang/slang-check-modifier.cpp
index 9734df4db..b38018354 100644
--- a/source/slang/slang-check-modifier.cpp
+++ b/source/slang/slang-check-modifier.cpp
@@ -477,7 +477,7 @@ namespace Slang
}
if (!typeChecked)
{
- arg = CheckExpr(arg);
+ arg = CheckTerm(arg);
arg = coerce(paramDecl->getType(), arg);
}
}
diff --git a/source/slang/slang-check-overload.cpp b/source/slang/slang-check-overload.cpp
index df5424659..0b2c61e18 100644
--- a/source/slang/slang-check-overload.cpp
+++ b/source/slang/slang-check-overload.cpp
@@ -1080,7 +1080,7 @@ namespace Slang
// So the question is then whether a mismatch during the
// unification step should be taken as an immediate failure...
- TryUnifyTypes(constraints, context.getArgType(aa), getType(m_astBuilder, params[aa]));
+ TryUnifyTypes(constraints, context.getArgTypeForInference(aa, this), getType(m_astBuilder, params[aa]));
#endif
}
}