Skip to content

Commit

Permalink
Resolve and test type of _wide_get_locale primitive
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Rift <[email protected]>
  • Loading branch information
riftEmber committed Dec 20, 2024
1 parent 738e257 commit 2b4f69f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/lib/resolution/prims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,6 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
case PRIM_BLOCK_UNLOCAL:
case PRIM_LOGICAL_FOLDER:
case PRIM_WIDE_MAKE:
case PRIM_WIDE_GET_LOCALE:
case PRIM_REGISTER_GLOBAL_VAR:
case PRIM_BROADCAST_GLOBAL_VARS:
case PRIM_PRIVATE_BROADCAST:
Expand All @@ -1791,6 +1790,11 @@ CallResolutionResult resolvePrimCall(ResolutionContext* rc,
CHPL_UNIMPL("misc primitives");
break;

case PRIM_WIDE_GET_LOCALE:
type = QualifiedType(QualifiedType::CONST_VAR,
CompositeType::getLocaleIDType(context));
break;

case PRIM_GATHER_TESTS:
type = primGatherTests(context, ci);
break;
Expand Down
23 changes: 23 additions & 0 deletions frontend/test/resolution/testResolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1759,6 +1759,28 @@ static void testPromotionPrim() {
assert(guard.realizeErrors() == 0);
}

// Test the '_wide_get_locale' primitive.
static void testGetLocalePrim() {
Context* context = buildStdContext();
ErrorGuard guard(context);

auto variables = resolveTypesOfVariables(context,
R"""(
var x : _ddata(real);
var locId = __primitive("_wide_get_locale", x);
var sublocId = chpl_sublocFromLocaleID(locId);
)""", { "locId", "sublocId" });

auto locId = variables.at("locId");
assert(locId.type());
assert(locId.type() == CompositeType::getLocaleIDType(context));
auto sublocId = variables.at("sublocId");
assert(sublocId.type());
assert(sublocId.type()->isIntType());

assert(guard.realizeErrors() == 0);
}

int main() {
test1();
test2();
Expand Down Expand Up @@ -1791,6 +1813,7 @@ int main() {
testInfiniteCycleBug();

testPromotionPrim();
testGetLocalePrim();

return 0;
}

0 comments on commit 2b4f69f

Please sign in to comment.