Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "Fix: `scalar` template parameter name conflict with each other",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
1 change: 1 addition & 0 deletions packages/compiler/core/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ export function createBinder(program: Program): Binder {
function hasScope(node: Node): node is ScopeNode {
switch (node.kind) {
case SyntaxKind.ModelStatement:
case SyntaxKind.ScalarStatement:
case SyntaxKind.AliasStatement:
case SyntaxKind.TypeSpecScript:
case SyntaxKind.InterfaceStatement:
Expand Down
14 changes: 14 additions & 0 deletions packages/compiler/test/checker/scalar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ describe("compiler: scalars", () => {
strictEqual(A.name, "A");
});

// https://github.com/microsoft/typespec/issues/1764
it("template parameter are scoped to the scalar", async () => {
const { A, B } = await runner.compile(`
@test @doc(T) scalar A<T extends string>;
@test @doc(T) scalar B<T extends string>;

alias AIns = A<"">;
alias BIns = B<"">;
`);

strictEqual(A.kind, "Scalar" as const);
strictEqual(B.kind, "Scalar" as const);
});

describe("custom scalars and default values", () => {
it("allows custom numeric scalar to have a default value", async () => {
const { S, M } = await runner.compile(`
Expand Down