Skip to content

Commit c6c3c12

Browse files
committed
Fix.
1 parent fe8de3b commit c6c3c12

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

source/slang/slang-check-constraint.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,13 @@ DeclRef<Decl> SemanticsVisitor::trySolveConstraintSystem(
573573
}
574574
auto& types = solvedArgs[typeParam->parameterIndex].types;
575575
// Fail if any of the resolved type element is empty.
576-
for (auto t : types)
576+
for (auto& t : types)
577577
{
578578
if (!t)
579579
return DeclRef<Decl>();
580+
// If the resolved type is an integer literal type, we should use its proper type.
581+
if (auto litType = as<IntLiteralType>(t))
582+
t = litType->getProperType();
580583
}
581584
if (!isPack)
582585
{

source/slang/slang-check-conversion.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,7 @@ bool SemanticsVisitor::_coerce(
14391439
outCost,
14401440
fromExpr ? fromExpr->loc : SourceLoc());
14411441
}
1442+
fromType = fromIntLitType->getProperType();
14421443
}
14431444

14441445
// A enum type can be converted into its underlying tag type.

source/slang/slang-check-expr.cpp

+32-9
Original file line numberDiff line numberDiff line change
@@ -2941,6 +2941,7 @@ Expr* SemanticsExprVisitor::convertToLogicOperatorExpr(InvokeExpr* expr)
29412941
bool shortCircuitSupport = true;
29422942
for (auto& arg : expr->arguments)
29432943
{
2944+
arg = maybeCoerceExprToProperIntType(arg);
29442945
if (!as<BasicExpressionType>(arg->type.type))
29452946
{
29462947
shortCircuitSupport = false;
@@ -3020,13 +3021,15 @@ Expr* SemanticsExprVisitor::visitInvokeExpr(InvokeExpr* expr)
30203021
{
30213022
arg = CheckExpr(arg);
30223023
}
3023-
if (auto result = tryFoldLiteralNegateExpr(expr))
3024-
return result;
3024+
30253025
// if the expression is '&&' or '||', we will convert it
30263026
// to use short-circuit evaluation.
30273027
if (auto newExpr = convertToLogicOperatorExpr(expr))
30283028
return newExpr;
30293029

3030+
if (auto result = tryFoldLiteralNegateExpr(expr))
3031+
return result;
3032+
30303033
expr->functionExpr = CheckTerm(expr->functionExpr);
30313034

30323035
if (auto baseType = as<DeclRefType>(expr->functionExpr->type))
@@ -4955,6 +4958,20 @@ Expr* SemanticsVisitor::checkGeneralMemberLookupExpr(MemberExpr* expr, Type* bas
49554958
return createLookupResultExpr(expr->name, lookupResult, expr->baseExpression, expr->loc, expr);
49564959
}
49574960

4961+
bool isValidVectorSwizzleName(Name* name)
4962+
{
4963+
if (!name)
4964+
return false;
4965+
if (name->text.getLength() > 4 || name->text.getLength() == 0)
4966+
return false;
4967+
for (auto ch : name->text)
4968+
{
4969+
if (ch < 'w' || ch > 'z')
4970+
return false;
4971+
}
4972+
return true;
4973+
}
4974+
49584975
Expr* SemanticsExprVisitor::visitMemberExpr(MemberExpr* expr)
49594976
{
49604977
bool needDeref = false;
@@ -4996,15 +5013,21 @@ Expr* SemanticsExprVisitor::visitMemberExpr(MemberExpr* expr)
49965013
}
49975014
if (auto baseVecType = as<VectorExpressionType>(baseType))
49985015
{
4999-
return CheckSwizzleExpr(
5000-
expr,
5001-
baseVecType->getElementType(),
5002-
baseVecType->getElementCount());
5016+
if (isValidVectorSwizzleName(expr->name))
5017+
{
5018+
return CheckSwizzleExpr(
5019+
expr,
5020+
baseVecType->getElementType(),
5021+
baseVecType->getElementCount());
5022+
}
50035023
}
5004-
else if (auto baseScalarType = as<BasicExpressionType>(baseType))
5024+
if (auto baseScalarType = as<BasicExpressionType>(baseType))
50055025
{
5006-
// Treat scalar like a 1-element vector when swizzling
5007-
return CheckSwizzleExpr(expr, baseScalarType, 1);
5026+
if (isValidVectorSwizzleName(expr->name))
5027+
{
5028+
// Treat scalar like a 1-element vector when swizzling
5029+
return CheckSwizzleExpr(expr, baseScalarType, 1);
5030+
}
50085031
}
50095032
else if (as<NamespaceType>(baseType))
50105033
{

0 commit comments

Comments
 (0)