From 1e5091d2b0295030654ba5659ae7680bc9e5fc40 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 10 Apr 2023 09:18:35 -0700 Subject: [PATCH 1/4] Fix scalar template params scope --- packages/compiler/core/binder.ts | 1 + packages/compiler/test/checker/scalar.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/compiler/core/binder.ts b/packages/compiler/core/binder.ts index ee60f4dd55e..e51b4a1345d 100644 --- a/packages/compiler/core/binder.ts +++ b/packages/compiler/core/binder.ts @@ -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: diff --git a/packages/compiler/test/checker/scalar.test.ts b/packages/compiler/test/checker/scalar.test.ts index f9a08750539..717a06c5dac 100644 --- a/packages/compiler/test/checker/scalar.test.ts +++ b/packages/compiler/test/checker/scalar.test.ts @@ -48,6 +48,17 @@ 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; + @test @doc(T) scalar 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(` From f2216eca7512524592edccadacf40277b0b007b8 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 10 Apr 2023 09:19:31 -0700 Subject: [PATCH 2/4] Changelog --- ...x-scalar-template-param-scope_2023-04-10-16-19.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@typespec/compiler/fix-scalar-template-param-scope_2023-04-10-16-19.json diff --git a/common/changes/@typespec/compiler/fix-scalar-template-param-scope_2023-04-10-16-19.json b/common/changes/@typespec/compiler/fix-scalar-template-param-scope_2023-04-10-16-19.json new file mode 100644 index 00000000000..d60c5d7cbd8 --- /dev/null +++ b/common/changes/@typespec/compiler/fix-scalar-template-param-scope_2023-04-10-16-19.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@typespec/compiler", + "comment": "Fix: `scalar` template parameter name conclict with each other", + "type": "none" + } + ], + "packageName": "@typespec/compiler" +} \ No newline at end of file From 2114e928839d02ad1ed63ca5f7f1d98238d470ad Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 10 Apr 2023 10:06:50 -0700 Subject: [PATCH 3/4] Fix test syntax --- packages/compiler/test/checker/scalar.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/compiler/test/checker/scalar.test.ts b/packages/compiler/test/checker/scalar.test.ts index 717a06c5dac..facacdca37a 100644 --- a/packages/compiler/test/checker/scalar.test.ts +++ b/packages/compiler/test/checker/scalar.test.ts @@ -51,8 +51,11 @@ describe("compiler: scalars", () => { // 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; - @test @doc(T) scalar B; + @test @doc(T) scalar A; + @test @doc(T) scalar B; + + alias AIns = A<"">; + alias BIns = B<"">; `); strictEqual(A.kind, "Scalar" as const); From e077f537f3ed643ec133b26d093cf9eda3bae7e8 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Mon, 10 Apr 2023 10:30:56 -0700 Subject: [PATCH 4/4] . --- .../fix-scalar-template-param-scope_2023-04-10-16-19.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/changes/@typespec/compiler/fix-scalar-template-param-scope_2023-04-10-16-19.json b/common/changes/@typespec/compiler/fix-scalar-template-param-scope_2023-04-10-16-19.json index d60c5d7cbd8..d93de2304c1 100644 --- a/common/changes/@typespec/compiler/fix-scalar-template-param-scope_2023-04-10-16-19.json +++ b/common/changes/@typespec/compiler/fix-scalar-template-param-scope_2023-04-10-16-19.json @@ -2,9 +2,9 @@ "changes": [ { "packageName": "@typespec/compiler", - "comment": "Fix: `scalar` template parameter name conclict with each other", + "comment": "Fix: `scalar` template parameter name conflict with each other", "type": "none" } ], "packageName": "@typespec/compiler" -} \ No newline at end of file +}