Skip to content

Commit

Permalink
Correct handling of unions of unions
Browse files Browse the repository at this point in the history
Resolves #2469
  • Loading branch information
Gerrit0 committed Jan 8, 2024
1 parent 7b558b0 commit ca15aad
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Bug Fixes

- Fixed an issue where a namespace would not be created for merged function-namespaces only containing types, #2476.
- Fixed an infinite loop when converting a union type which directly contained another union type which refers to itself, #2469.

## v0.25.6 (2024-01-01)

Expand Down
7 changes: 1 addition & 6 deletions src/lib/converter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,7 @@ export function convertType(
// We need to check it here, not just in the union checker, because typeToTypeNode
// will use the origin when serializing
// aliasSymbol check is important - #2468
if (
typeOrNode.isUnion() &&
typeOrNode.origin &&
!typeOrNode.origin.isUnion() &&
!typeOrNode.aliasSymbol
) {
if (typeOrNode.isUnion() && typeOrNode.origin && !typeOrNode.aliasSymbol) {
return convertType(context, typeOrNode.origin);
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/TestLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ export class TestLogger extends Logger {
this.messages.splice(index, 1);
}

expectNoMessage(message: string) {
const regex = createRegex(message);
const index = this.messages.findIndex((m) => regex.test(m));
if (index !== -1) {
const messages = this.messages.join("\n\t");
fail(
`Expected "${message}" to not be logged. The logged messages were:\n\t${messages}`,
);
}
}

expectNoOtherMessages({ ignoreDebug } = { ignoreDebug: true }) {
const messages = ignoreDebug
? this.messages.filter((msg) => !msg.startsWith("debug"))
Expand Down
9 changes: 6 additions & 3 deletions src/test/behavior.c2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,12 +1086,15 @@ describe("Behavior Tests", () => {
logger.expectNoOtherMessages();
});

it("Should not produce warnings when processing an object type twice due to intersection", () => {
it("Should not warn about recursive types", () => {
const project = convert("refusingToRecurse");
const schemaTypeBased = query(project, "schemaTypeBased");
equal(schemaTypeBased.type?.toString(), "Object & Object");
equal(
querySig(project, "Map.getFilter").type?.toString(),
"void | ExpressionSpecification",
);

logger.expectMessage("debug: Begin readme.md*");
logger.expectNoOtherMessages({ ignoreDebug: false });
logger.expectNoMessage("debug: Refusing to recurse*");
});
});
18 changes: 12 additions & 6 deletions src/test/converter/variables/specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -925,8 +925,10 @@
}
],
"type": {
"type": "unknown",
"name": "{ success: (successCallback: () => any) => ...; error: (errorCallback: () => any) => ...; finally: (finallyCallback: () => any) => ...; }"
"type": "reference",
"target": 55,
"name": "__object",
"package": "typedoc"
}
}
]
Expand Down Expand Up @@ -1028,8 +1030,10 @@
}
],
"type": {
"type": "unknown",
"name": "{ success: (successCallback: () => any) => ...; error: (errorCallback: () => any) => ...; finally: (finallyCallback: () => any) => ...; }"
"type": "reference",
"target": 55,
"name": "__object",
"package": "typedoc"
}
}
]
Expand Down Expand Up @@ -1131,8 +1135,10 @@
}
],
"type": {
"type": "unknown",
"name": "{ success: (successCallback: () => any) => ...; error: (errorCallback: () => any) => ...; finally: (finallyCallback: () => any) => ...; }"
"type": "reference",
"target": 55,
"name": "__object",
"package": "typedoc"
}
}
]
Expand Down
14 changes: 14 additions & 0 deletions src/test/converter2/behavior/refusingToRecurse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,17 @@ export const schema = {
export type Schema = FromSchema<typeof schema>;

export const schemaTypeBased = null! as Schema;

export type ExpressionSpecification =
| ["array", unknown | ExpressionSpecification]
| [
"array",
string | ExpressionSpecification,
unknown | ExpressionSpecification,
];

export class Map {
getFilter(layerId: string): ExpressionSpecification | void {
return;
}
}

0 comments on commit ca15aad

Please sign in to comment.