Skip to content

Commit

Permalink
Fix getArgumentValueFloat when arg is int. (#5888)
Browse files Browse the repository at this point in the history
* Fix `getArgumentValueFloat` when arg is int.

* format code

---------

Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
  • Loading branch information
csyonghe and slangbot authored Dec 17, 2024
1 parent 9c9e1f7 commit d61bba8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions source/slang/slang-reflection-api.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// slang-reflection-api.cpp

#include "../core/slang-basic.h"
#include "slang-check-impl.h"
#include "slang-check.h"
#include "slang-compiler.h"
#include "slang-syntax.h"
Expand Down Expand Up @@ -353,6 +354,15 @@ SLANG_API SlangResult spReflectionUserAttribute_GetArgumentValueFloat(
*rs = (float)cexpr->value;
return 0;
}
else if (auto implicitCastExpr = as<ImplicitCastExpr>(userAttr->args[index]))
{
auto base = implicitCastExpr->arguments[0];
if (auto intLit = as<IntegerLiteralExpr>(base))
{
*rs = (float)intLit->value;
return 0;
}
}
return SLANG_E_INVALID_ARG;
}
SLANG_API const char* spReflectionUserAttribute_GetArgumentValueString(
Expand Down
7 changes: 6 additions & 1 deletion tools/slang-unit-test/unit-test-attribute-reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ SLANG_UNIT_TEST(attributeReflection)
public struct NormalTextureAttribute
{
public E Type;
public float x;
};
[COM("042BE50B-CB01-4DBB-8367-3A9CDCBE2F49")]
interface IInterface { void f(); }
[NormalTexture(E.V1)]
[NormalTexture(E.V1, 6)]
struct TS {};
)";
String userSource = userSourceBody;
Expand Down Expand Up @@ -76,4 +77,8 @@ SLANG_UNIT_TEST(attributeReflection)
int value = 0;
normalTextureAttribute->getArgumentValueInt(0, &value);
SLANG_CHECK(value == 1);

float fvalue = 0;
normalTextureAttribute->getArgumentValueFloat(1, &fvalue);
SLANG_CHECK(fvalue == 6.0);
}

0 comments on commit d61bba8

Please sign in to comment.