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

Handle struct returns with one primitive field #742

Merged
4 changes: 2 additions & 2 deletions core/src/hir/type_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl TypeContext {
)
}

pub fn all_traits<'tcx>(&'tcx self) -> impl Iterator<Item = (TraitId, &TraitDef)> {
pub fn all_traits<'tcx>(&'tcx self) -> impl Iterator<Item = (TraitId, &'tcx TraitDef)> {
self.traits
.iter()
.enumerate()
Expand Down Expand Up @@ -203,7 +203,7 @@ impl TypeContext {
pub(super) fn from_ast_without_validation<'ast>(
env: &'ast Env,
attr_validator: impl AttributeValidator + 'static,
) -> Result<(LoweringContext, Self), Vec<ErrorAndContext>> {
) -> Result<(LoweringContext<'ast>, Self), Vec<ErrorAndContext>> {
let mut ast_out_structs = SmallVec::<[_; 16]>::new();
let mut ast_structs = SmallVec::<[_; 16]>::new();
let mut ast_opaques = SmallVec::<[_; 16]>::new();
Expand Down
3 changes: 3 additions & 0 deletions feature_tests/c/include/CyclicStructB.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions feature_tests/cpp/include/CyclicStructB.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions feature_tests/cpp/include/CyclicStructB.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions feature_tests/dart/lib/src/CyclicStructB.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions feature_tests/dart/lib/src/lib.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions feature_tests/js/api/CyclicStructA.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions feature_tests/js/api/CyclicStructB.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions feature_tests/js/api/CyclicStructB.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions feature_tests/js/api/CyclicStructC.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion feature_tests/js/test/struct-ts.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { MyEnum, MyStruct } from "diplomat-wasm-js-feature-tests";
import { MyEnum, MyStruct, CyclicStructB } from "diplomat-wasm-js-feature-tests";
test("Verify invariants of struct", t => {
const s = MyStruct.new_();
t.is(s.a, 17);
Expand All @@ -23,3 +23,11 @@ test("Test struct creation", t => {
});
t.is(s.intoA(), 17);
});
test("Function Returning Nested Struct of One Field", t => {
const a = CyclicStructB.getA();
t.is(a.cyclicOut(), "0");
});
test("Function De-Referencing Nested Struct of One Primitive", t => {
const a = CyclicStructB.getAOption();
t.is(a.cyclicOut(), "0");
});
12 changes: 11 additions & 1 deletion feature_tests/js/test/struct-ts.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { MyEnum, MyStruct } from "diplomat-wasm-js-feature-tests";
import { MyEnum, MyStruct, CyclicStructB } from "diplomat-wasm-js-feature-tests";

test("Verify invariants of struct", t => {
const s = MyStruct.new_();
Expand All @@ -24,4 +24,14 @@ test("Test struct creation", t => {
g: MyEnum.B
});
t.is(s.intoA(), 17);
});

test("Function Returning Nested Struct of One Field", t => {
const a = CyclicStructB.getA();
t.is(a.cyclicOut(), "0");
});

test("Function De-Referencing Nested Struct of One Primitive", t => {
const a = CyclicStructB.getAOption();
t.is(a.cyclicOut(), "0");
});
12 changes: 11 additions & 1 deletion feature_tests/js/test/struct.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import { MyEnum, MyStruct, ScalarPairWithPadding, BigStructWithStuff } from "diplomat-wasm-js-feature-tests";
import { MyEnum, MyStruct, ScalarPairWithPadding, BigStructWithStuff, CyclicStructB } from "diplomat-wasm-js-feature-tests";

test("Verify invariants of struct", t => {
const s = MyStruct.new_("hello");
Expand Down Expand Up @@ -46,3 +46,13 @@ test("Test struct layout: complex struct with multiple padding types and contain
s.assertValue(853);
t.is(true, true); // Ava doesn't like tests without assertions
});

test("Function Returning Nested Struct of One Primitive", t => {
const a = CyclicStructB.getA();
t.is(a.cyclicOut(), "0");
});

test("Function De-Referencing Nested Struct of One Primitive", t => {
const a = CyclicStructB.getAOption();
t.is(a.cyclicOut(), "0");
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions feature_tests/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ pub mod ffi {
pub fn get_a() -> CyclicStructA {
Default::default()
}

pub fn get_a_option() -> Option<CyclicStructA> {
Some(Default::default())
}
}

impl CyclicStructC {
Expand Down
Loading
Loading