Skip to content

Commit

Permalink
Fix #884 - wrong union predication about constant type (#886)
Browse files Browse the repository at this point in the history
When there's same type exists in both `atomics` and `constants` and try to predicate union type about that case, `typia` mis-computes whether each types are intersected or not.

This PR fixes the bug, just by adding the special logic about the same typed `atomics` and `constants` are compatible.
  • Loading branch information
samchon authored Nov 27, 2023
1 parent 05e25ec commit 5d37062
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "5.3.0",
"version": "5.3.1-dev.20231127-4",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/benchmark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^2.5.13",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.3.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.1-dev.20231127-4.tgz"
}
}
2 changes: 1 addition & 1 deletion packages/errors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"typescript": "^5.3.2"
},
"dependencies": {
"typia": "D:\\github\\samchon\\typia\\typia-5.3.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.1-dev.20231127-4.tgz"
}
}
2 changes: 1 addition & 1 deletion packages/test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"suppress-warnings": "^1.0.2",
"tstl": "^2.5.13",
"uuid": "^9.0.1",
"typia": "D:\\github\\samchon\\typia\\typia-5.3.0.tgz"
"typia": "D:\\github\\samchon\\typia\\typia-5.3.1-dev.20231127-4.tgz"
}
}
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "5.3.0",
"version": "5.3.1-dev.20231127-4",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -56,7 +56,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "5.3.0"
"typia": "5.3.1-dev.20231127-4"
},
"peerDependencies": {
"typescript": ">=4.8.0 <5.4.0"
Expand Down
18 changes: 17 additions & 1 deletion src/schemas/metadata/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,18 @@ export namespace Metadata {
// VALUES
//----
// ATOMICS
for (const atomic of x.atomics)
for (const atomic of x.atomics) {
if (y.atomics.some((ya) => atomic.type === ya.type)) return true;
if (y.constants.some((yc) => atomic.type === yc.type)) return true;
}

// CONSTANTS
for (const constant of x.constants) {
const atomic: MetadataAtomic | undefined = y.atomics.find(
(elem) => elem.type === constant.type,
);
if (atomic !== undefined) return true;

const opposite: MetadataConstant | undefined = y.constants.find(
(elem) => elem.type === constant.type,
);
Expand All @@ -339,6 +346,15 @@ export namespace Metadata {
if (values.size !== constant.values.length + opposite.values.length)
return true;
}

// TEMPLATES
if (!!x.templates.length && y.atomics.some((ya) => ya.type === "string"))
return true;
else if (
!!y.templates.length &&
x.atomics.some((xa) => xa.type === "string")
)
return true;
return false;
};

Expand Down

0 comments on commit 5d37062

Please sign in to comment.