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 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
14 changes: 14 additions & 0 deletions examples/tests/invalid/json_values.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 });
// ^^^^^^^^^^^^^^^ "MutArray<num>" is not a legal JSON value
takeJson({ values: map });
// ^^^^^^^^^^^^^^^ "MutMap<str>" is not a legal JSON value
11 changes: 11 additions & 0 deletions examples/tests/valid/json-types.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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)
};

1 change: 1 addition & 0 deletions libs/wingc/src/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,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
20 changes: 20 additions & 0 deletions tools/hangar/__snapshots__/invalid.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3303,6 +3303,26 @@ Test Files 1 failed (1)
Duration <DURATION>"
`;

exports[`json_values.test.w 1`] = `
"error: "MutArray<num>" is not a legal JSON value
--> ../../../examples/tests/invalid/json_values.test.w:11:20
|
11 | takeJson({ values: arr });
| ^^^


error: "MutMap<str>" is not a legal JSON value
--> ../../../examples/tests/invalid/json_values.test.w:13:20
|
13 | takeJson({ values: map });
| ^^^

Tests 1 failed (1)
Snapshots 1 skipped
Test Files 1 failed (1)
Duration <DURATION>"
`;

exports[`map_entries.test.w 1`] = `
"error: Expected type to be "str", but got "num" instead
--> ../../../examples/tests/invalid/map_entries.test.w:2:20
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# [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 $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