Skip to content

Commit

Permalink
Fix it better
Browse files Browse the repository at this point in the history
  • Loading branch information
drew-y committed Aug 31, 2024
1 parent df940b5 commit d670b36
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/semantics/check-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const checkObjectInit = (call: Call, type: ObjectType): ObjectLiteral => {
}

// Check to ensure literal structure is compatible with nominal structure
if (!typesAreEquivalent(type, literal.type, true)) {
if (!typesAreEquivalent(literal.type, type, true)) {
throw new Error(`Object literal type does not match expected type`);
}

Expand Down Expand Up @@ -486,11 +486,13 @@ const resolveCallFn = (call: Call): Fn | undefined => {
}
const argLabel = getExprLabel(arg);
const labelsMatch = p.label === argLabel;
return typesAreEquivalent(p.type!, argType) && labelsMatch;
return typesAreEquivalent(argType, p.type!) && labelsMatch;
});
});

if (!candidates) return undefined;
if (!candidates.length) {
return undefined;
}
if (candidates.length === 1) return candidates[0];
return findBestFnMatch(candidates, call);
};
Expand Down Expand Up @@ -562,8 +564,8 @@ const typesAreEquivalent = (
if (a.isObjectType() && b.isObjectType()) {
return (
(ignoreExtension || a.extends(b)) &&
a.fields.every((field) => {
const match = b.fields.find((f) => f.name === field.name);
b.fields.every((field) => {
const match = a.fields.find((f) => f.name === field.name);
return match && typesAreEquivalent(field.type, match.type);
})
);
Expand Down

0 comments on commit d670b36

Please sign in to comment.