Skip to content

Commit

Permalink
Add unixtimestamp32 to standard lib (microsoft#2579)
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin authored and tjprescott committed Oct 18, 2023
1 parent 8d24f2f commit 0801e17
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/compiler/src/core/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,7 @@ export function createChecker(program: Program): Checker {
}
for (const prop of node.properties) {
if (prop.kind === SyntaxKind.ModelSpreadProperty) {
checkForSelfReference(prop, node);
resolveAndCopyMembers(prop.target);
} else {
const name = prop.id.sv;
Expand Down Expand Up @@ -2737,6 +2738,29 @@ export function createChecker(program: Program): Checker {
}
}

function checkForSelfReference(node: ModelSpreadPropertyNode, parent: ModelStatementNode) {
let targetName = "";
let parentName = "";
if (node.target.target.kind === SyntaxKind.Identifier) {
targetName = node.target.target.sv;
}
if (parent.kind === SyntaxKind.ModelStatement) {
parentName = parent.id.sv;
}
if (parentName === "" || targetName === "") {
return;
}
if (parentName === targetName) {
reportCheckerDiagnostic(
createDiagnostic({
code: "spread-model",
messageId: "selfSpread",
target: node,
})
);
}
}

function resolveAliasedSymbol(ref: Sym): Sym | undefined {
const node = ref.declarations[0] as AliasStatementNode;
switch (node.value.kind) {
Expand Down
1 change: 1 addition & 0 deletions packages/compiler/src/core/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ const diagnostics = {
messages: {
default: "Cannot spread properties of non-model type.",
neverIndex: "Cannot spread type because it cannot hold properties.",
selfSpread: "Cannot spread type within its own declaration.",
},
},
"unsupported-default": {
Expand Down
14 changes: 14 additions & 0 deletions packages/compiler/test/checker/spread.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ describe("compiler: spread", () => {
});
});

it("emit diagnostic if model spreads itself", async () => {
const diagnostics = await runner.diagnose(`
model Foo {
...Foo,
name: string,
}
`);

expectDiagnostics(diagnostics, {
code: "spread-model",
message: "Cannot spread type within its own declaration.",
});
});

it("emit diagnostic if spreading scalar type", async () => {
const diagnostics = await runner.diagnose(`
model Foo {
Expand Down

0 comments on commit 0801e17

Please sign in to comment.