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: expected type to be Array<Json>, but got Array<Json> instead #6999

Merged
merged 7 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
25 changes: 25 additions & 0 deletions examples/tests/valid/json-types.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


let extra = MutArray<Json>["bar"];
let base = [Json "foo"];
base.concat(extra.copy());

let base2 = Array<Json>["foo"];

let obj = {
first: "ok",
second: ["cool"].concat(base2)
};

let arr = MutArray<num>[1, 2, 3];
arr.push(4);

let map = MutMap<str>{"a" => "1"};
map.set("b", "2");

let takeJson = (obj: Json) => {

};

takeJson({ values: arr });
takeJson({ values: map });
Chriscbr marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions libs/wingc/src/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ impl Subtype for Type {
(Self::Number, Self::Stringable) => true,
(Self::Boolean, Self::Stringable) => true,
(Self::Json(_), Self::Stringable) => true,
(Self::Json(_), Self::Json(_)) => true,
(Self::MutJson, Self::Stringable) => true,
(Self::Enum(_), Self::Stringable) => true,
_ => false,
Expand Down Expand Up @@ -1269,7 +1270,9 @@ impl TypeRef {
Type::Boolean => true,
Type::MutJson | Type::Json(None) => true,
Type::Inferred(..) => true,
Type::MutArray(v) => v.is_json_legal_value(),
Type::Array(v) => v.is_json_legal_value(),
Type::MutMap(v) => v.is_json_legal_value(),
Type::Map(v) => v.is_json_legal_value(),
Type::Struct(ref s) => {
for t in s.fields(true).map(|(_, v)| v.type_) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# [json-types.test.w](../../../../../examples/tests/valid/json-types.test.w) | compile | tf-aws

## main.tf.json
```json
{
"//": {
"metadata": {
"backend": "local",
"stackName": "root"
},
"outputs": {}
},
"provider": {
"aws": [
{}
]
}
}
```

## preflight.cjs
```cjs
"use strict";
const $stdlib = require('@winglang/sdk');
const $macros = require("@winglang/sdk/lib/macros");
const $platforms = ((s) => !s ? [] : s.split(';'))(process.env.WING_PLATFORMS);
const $outdir = process.env.WING_SYNTH_DIR ?? ".";
const $wing_is_test = process.env.WING_IS_TEST === "true";
const std = $stdlib.std;
const $helpers = $stdlib.helpers;
const $extern = $helpers.createExternRequire(__dirname);
const $PlatformManager = new $stdlib.platform.PlatformManager({platformPaths: $platforms});
class $Root extends $stdlib.std.Resource {
constructor($scope, $id) {
super($scope, $id);
$helpers.nodeof(this).root.$preflightTypesMap = { };
let $preflightTypesMap = {};
$helpers.nodeof(this).root.$preflightTypesMap = $preflightTypesMap;
const extra = ["bar"];
const base = ["foo"];
(base.concat($macros.__MutArray_copy(false, extra, )));
const base2 = ["foo"];
const obj = ({"first": "ok", "second": (["cool"].concat(base2))});
const arr = [1, 2, 3];
$macros.__MutArray_push(false, arr, 4);
const map = ({["a"]: "1"});
$macros.__MutMap_set(false, map, "b", "2");
const takeJson = ((obj) => {
});
(takeJson(({"values": arr})));
(takeJson(({"values": map})));
}
}
const $APP = $PlatformManager.createApp({ outdir: $outdir, name: "json-types.test", rootConstruct: $Root, isTestEnvironment: $wing_is_test, entrypointDir: process.env['WING_SOURCE_DIR'], rootId: process.env['WING_ROOT_ID'] });
$APP.synth();
//# sourceMappingURL=preflight.cjs.map
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# [json-types.test.w](../../../../../examples/tests/valid/json-types.test.w) | test | sim

## stdout.log
```log
pass ─ json-types.test.wsim (no tests)

Tests 1 passed (1)
Snapshots 1 skipped
Test Files 1 passed (1)
Duration <DURATION>
```

Loading