summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-check-conversion.cpp
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2025-05-15 01:55:17 +0000
committerGitHub <noreply@github.com>2025-05-15 01:55:17 +0000
commit2275e18fc052239fe67f3fda68252ad92bb83ca9 (patch)
tree19cdf1917811e1c40362ef468c5d3d6a20344517 /source/slang/slang-check-conversion.cpp
parent8c98714df2198db1aff4ce6c6f7922850e400f80 (diff)
Do not print errors in _coerce when "JustTrying". (#7064)
* Do not print errors in _coerce when "JustTrying". While figuring out which generic-overload works best, `_coerce()` is printing errors and Slang compilation terminates prematurely. When `TryCheckGenericOverloadCandidateTypes()` is calling `_coerce()` in "JustTrying" mode, the error messages should be snoozed. The following logic shows the intention of how to silence the error messages, but the chain of `sink` was broken in the middle and `_coerce()` was using `getSink()` from the SemanticVisitor. val = ExtractGenericArgInteger( arg, getType(m_astBuilder, valParamRef), context.mode == OverloadResolveContext::Mode::JustTrying ? nullptr : getSink()); * Use tempSink when available.
Diffstat (limited to 'source/slang/slang-check-conversion.cpp')
-rw-r--r--source/slang/slang-check-conversion.cpp80
1 files changed, 53 insertions, 27 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index a2cb0f91b..68e5df7ce 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -137,6 +137,7 @@ bool SemanticsVisitor::_readValueFromInitializerList(
outToExpr,
firstInitExpr->type,
firstInitExpr,
+ getSink(),
nullptr);
}
@@ -491,7 +492,14 @@ bool SemanticsVisitor::_readAggregateValueFromInitializerList(
if (ioArgIndex < argCount)
{
auto arg = fromInitializerListExpr->args[ioArgIndex++];
- return _coerce(CoercionSite::Initializer, toType, outToExpr, arg->type, arg, nullptr);
+ return _coerce(
+ CoercionSite::Initializer,
+ toType,
+ outToExpr,
+ arg->type,
+ arg,
+ getSink(),
+ nullptr);
}
else
{
@@ -882,7 +890,7 @@ bool SemanticsVisitor::_coerceInitializerList(
// composition this shouldn't fail.
if (!as<InitializerListType>(fromInitializerListExpr->type) &&
!canCoerce(toType, fromInitializerListExpr->type, nullptr))
- return _failedCoercion(toType, outToExpr, fromInitializerListExpr);
+ return _failedCoercion(toType, outToExpr, fromInitializerListExpr, getSink());
// Try to invoke the user-defined constructor if it exists. This call will
// report error diagnostics if the used-defined constructor exists but does not
@@ -921,7 +929,11 @@ bool SemanticsVisitor::_coerceInitializerList(
return true;
}
-bool SemanticsVisitor::_failedCoercion(Type* toType, Expr** outToExpr, Expr* fromExpr)
+bool SemanticsVisitor::_failedCoercion(
+ Type* toType,
+ Expr** outToExpr,
+ Expr* fromExpr,
+ DiagnosticSink* sink)
{
if (outToExpr)
{
@@ -936,7 +948,10 @@ bool SemanticsVisitor::_failedCoercion(Type* toType, Expr** outToExpr, Expr* fro
}
else
{
- getSink()->diagnose(fromExpr->loc, Diagnostics::typeMismatch, toType, fromExpr->type);
+ if (sink)
+ {
+ sink->diagnose(fromExpr->loc, Diagnostics::typeMismatch, toType, fromExpr->type);
+ }
}
}
return false;
@@ -1108,6 +1123,7 @@ bool SemanticsVisitor::_coerce(
Expr** outToExpr,
QualType fromType,
Expr* fromExpr,
+ DiagnosticSink* sink,
ConversionCost* outCost)
{
// If we are about to try and coerce an overloaded expression,
@@ -1227,7 +1243,7 @@ bool SemanticsVisitor::_coerce(
//
if (!_canModifierBeAddedDuringCoercion(modifier))
{
- return _failedCoercion(toType, outToExpr, fromExpr);
+ return _failedCoercion(toType, outToExpr, fromExpr, sink);
}
}
}
@@ -1246,7 +1262,7 @@ bool SemanticsVisitor::_coerce(
//
if (!_canModifierBeDroppedDuringCoercion(modifier))
{
- return _failedCoercion(toType, outToExpr, fromExpr);
+ return _failedCoercion(toType, outToExpr, fromExpr, sink);
}
}
}
@@ -1425,7 +1441,7 @@ bool SemanticsVisitor::_coerce(
//
if (as<ParameterGroupType>(toType))
{
- return _failedCoercion(toType, outToExpr, fromExpr);
+ return _failedCoercion(toType, outToExpr, fromExpr, sink);
}
// We allow implicit conversion of a parameter group type like
@@ -1451,7 +1467,7 @@ bool SemanticsVisitor::_coerce(
derefExpr->checked = true;
}
- if (!_coerce(site, toType, outToExpr, fromElementType, derefExpr, &subCost))
+ if (!_coerce(site, toType, outToExpr, fromElementType, derefExpr, sink, &subCost))
{
return false;
}
@@ -1503,7 +1519,7 @@ bool SemanticsVisitor::_coerce(
openRefExpr = maybeOpenRef(fromExpr);
}
- if (!_coerce(site, toType, outToExpr, fromValueType, openRefExpr, &subCost))
+ if (!_coerce(site, toType, outToExpr, fromValueType, openRefExpr, sink, &subCost))
{
return false;
}
@@ -1550,7 +1566,7 @@ bool SemanticsVisitor::_coerce(
if (cachedMethod->conversionFuncOverloadCandidate.status !=
OverloadCandidate::Status::Applicable)
{
- return _failedCoercion(toType, outToExpr, fromExpr);
+ return _failedCoercion(toType, outToExpr, fromExpr, sink);
}
overloadContext.bestCandidateStorage = cachedMethod->conversionFuncOverloadCandidate;
overloadContext.bestCandidate = &overloadContext.bestCandidateStorage;
@@ -1594,7 +1610,7 @@ bool SemanticsVisitor::_coerce(
{
getShared()->cacheImplicitCastMethod(implicitCastKey, ImplicitCastMethod{});
}
- return _failedCoercion(toType, outToExpr, fromExpr);
+ return _failedCoercion(toType, outToExpr, fromExpr, sink);
}
// If all of the candidates in `bestCandidates` are applicable,
@@ -1622,7 +1638,10 @@ bool SemanticsVisitor::_coerce(
//
if (outToExpr)
{
- getSink()->diagnose(fromExpr, Diagnostics::ambiguousConversion, fromType, toType);
+ if (sink)
+ {
+ sink->diagnose(fromExpr, Diagnostics::ambiguousConversion, fromType, toType);
+ }
*outToExpr = CreateErrorExpr(fromExpr);
}
@@ -1653,7 +1672,7 @@ bool SemanticsVisitor::_coerce(
{
getShared()->cacheImplicitCastMethod(implicitCastKey, ImplicitCastMethod{});
}
- return _failedCoercion(toType, outToExpr, fromExpr);
+ return _failedCoercion(toType, outToExpr, fromExpr, sink);
}
// Next, we need to look at the implicit conversion
@@ -1675,12 +1694,15 @@ bool SemanticsVisitor::_coerce(
{
if (cost >= kConversionCost_Explicit)
{
- getSink()->diagnose(fromExpr, Diagnostics::typeMismatch, toType, fromType);
- getSink()->diagnoseWithoutSourceView(
- fromExpr,
- Diagnostics::noteExplicitConversionPossible,
- fromType,
- toType);
+ if (sink)
+ {
+ sink->diagnose(fromExpr, Diagnostics::typeMismatch, toType, fromType);
+ sink->diagnoseWithoutSourceView(
+ fromExpr,
+ Diagnostics::noteExplicitConversionPossible,
+ fromType,
+ toType);
+ }
}
else if (cost >= kConversionCost_Default)
{
@@ -1704,9 +1726,9 @@ bool SemanticsVisitor::_coerce(
}
}
}
- if (shouldEmitGeneralWarning)
+ if (shouldEmitGeneralWarning && sink)
{
- getSink()->diagnose(
+ sink->diagnose(
fromExpr,
Diagnostics::unrecommendedImplicitConversion,
fromType,
@@ -1714,14 +1736,14 @@ bool SemanticsVisitor::_coerce(
}
}
- if (site == CoercionSite::Argument)
+ if (site == CoercionSite::Argument && sink)
{
auto builtinConversionKind = getImplicitConversionBuiltinKind(
overloadContext.bestCandidate->item.declRef.getDecl());
if (builtinConversionKind == kBuiltinConversion_FloatToDouble)
{
if (!as<FloatingPointLiteralExpr>(fromExpr))
- getSink()->diagnose(fromExpr, Diagnostics::implicitConversionToDouble);
+ sink->diagnose(fromExpr, Diagnostics::implicitConversionToDouble);
}
}
}
@@ -1788,7 +1810,7 @@ bool SemanticsVisitor::_coerce(
{
getShared()->cacheImplicitCastMethod(implicitCastKey, ImplicitCastMethod{});
}
- return _failedCoercion(toType, outToExpr, fromExpr);
+ return _failedCoercion(toType, outToExpr, fromExpr, sink);
}
bool SemanticsVisitor::canCoerce(
@@ -1830,7 +1852,7 @@ bool SemanticsVisitor::canCoerce(
// which suppresses emission of any diagnostics
// during the coercion process.
//
- bool rs = _coerce(CoercionSite::General, toType, nullptr, fromType, fromExpr, &cost);
+ bool rs = _coerce(CoercionSite::General, toType, nullptr, fromType, fromExpr, getSink(), &cost);
if (outCost)
*outCost = cost;
@@ -1887,10 +1909,14 @@ Expr* SemanticsVisitor::createModifierCastExpr(Type* toType, Expr* fromExpr)
}
-Expr* SemanticsVisitor::coerce(CoercionSite site, Type* toType, Expr* fromExpr)
+Expr* SemanticsVisitor::coerce(
+ CoercionSite site,
+ Type* toType,
+ Expr* fromExpr,
+ DiagnosticSink* sink)
{
Expr* expr = nullptr;
- if (!_coerce(site, toType, &expr, fromExpr->type, fromExpr, nullptr))
+ if (!_coerce(site, toType, &expr, fromExpr->type, fromExpr, sink, nullptr))
{
// Note(tfoley): We don't call `CreateErrorExpr` here, because that would
// clobber the type on `fromExpr`, and an invariant here is that coercion