Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inherent type of type desc missing #43883

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@
*/
package io.ballerina.runtime.internal.values;

import java.util.Map;
import java.util.Optional;

import static io.ballerina.runtime.api.utils.TypeUtils.getImpliedType;

import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.types.Type;
import io.ballerina.runtime.api.types.TypeTags;
import io.ballerina.runtime.api.types.semtype.BasicTypeBitSet;
import io.ballerina.runtime.api.types.semtype.Builder;
import io.ballerina.runtime.api.types.semtype.Context;
import io.ballerina.runtime.api.types.semtype.SemType;
import io.ballerina.runtime.api.utils.StringUtils;
import io.ballerina.runtime.api.values.BInitialValueEntry;
import io.ballerina.runtime.api.values.BLink;
Expand All @@ -33,10 +40,6 @@
import io.ballerina.runtime.internal.types.BAnnotatableType;
import io.ballerina.runtime.internal.types.BTypedescType;

import java.util.Map;

import static io.ballerina.runtime.api.utils.TypeUtils.getImpliedType;

/**
* <p>
* Ballerina runtime value representation of a *type*. This class will be extended by the generated
Expand Down Expand Up @@ -160,4 +163,9 @@ public BTypedesc getTypedesc() {
public Object frozenCopy(Map<Object, Object> refs) {
return this;
}

@Override
public Optional<SemType> inherentTypeOf(Context cx) {
return Optional.of(SemType.tryInto(cx, getType()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.ballerinalang.test.types.typedesc;

import static org.ballerinalang.test.BAssertUtil.validateError;

import io.ballerina.runtime.api.types.TypeTags;
import io.ballerina.runtime.api.values.BArray;
import io.ballerina.runtime.api.values.BTypedesc;
Expand All @@ -27,8 +29,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static org.ballerinalang.test.BAssertUtil.validateError;

/**
* This class contains typedesc type related test cases.
*/
Expand Down Expand Up @@ -82,6 +82,11 @@ public void testBasicTypes() {
Assert.assertEquals(returns.get(4).toString(), "typedesc byte");
}

@Test(description = "Test type desc shapes")
public void testTypeDescShape() {
BRunUtil.invoke(result, "testRecordWithTypedescField");
}

@Test(description = "Test buildin ref types")
public void testRefTypes() {
BRunUtil.invoke(result, "testRefTypes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ function testTypeDefWithFunctionTypeDescAsTypedesc() {
assertEquality("typedesc function () returns (string)", d.toString());
}

type TD1 record {
readonly int foo;
readonly typedesc<int> entity;
};

type TD2 record {
10 foo;
typedesc<10> entity;
};

function testRecordWithTypedescField() {
int foo = 10;
typedesc<int> typeOfFoo = typeof foo;
TD1 td1 = {foo, entity: typeOfFoo};
assertEquality(td1 is TD2, true);
}


const ASSERTION_ERROR_REASON = "AssertionError";

function assertEquality(any|error expected, any|error actual) {
Expand Down
Loading