Skip to content

resolve default template parameters from parent containers #6938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

chrisradek
Copy link
Member

Meant to partially address #6745

The extends case still acts oddly (and may be fixed when #6699 is fixed).

This case still won't produce any output:

interface Resource<T> {
  read<U = T>(): U;
}

model Foo {
  type: "foo";
}

interface FooResource extends Resource<Foo> {}

Because even though all the Resource template parameters are provided in the extends, the operation in FooResource does not get instantiated. I'm not 100% convinced this case is a bug though.

Copy link
Contributor

github-actions bot commented Apr 9, 2025

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - fix ✏️

Fixes template argument resolution when a default template parameter value is resolved by a parent container (e.g. interface),> For example:,> tsp,> interface Resource<T> {,> read<U = T>(): U;,> },> ,> model Foo {,> type: "foo";,> },> ,> alias FooResource = Resource<Foo>;,> ,> op readFoo is FooResource.read;,> ,> The returnType for readFoo would be model Foo. Previously the returnType resolved to a TemplateParameter.

@@ -4316,9 +4330,6 @@ export function createChecker(program: Program, resolver: NameResolver): Checker
type.name,
SymbolFlags.Interface | SymbolFlags.LateBound,
);
if (isTemplateInstance(type) && type.name === "Foo") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@azure-sdk
Copy link
Collaborator

azure-sdk commented Apr 9, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@chrisradek chrisradek enabled auto-merge April 11, 2025 20:04
@steverice
Copy link
Contributor

Hey @chrisradek , thanks for the fix.

I still encounter the error with this case:

interface A<T = {}> {
  op foo<R = T, P = R>(params: P): R;
}
op MyOp is A.foo;

(playground)

I'd expect that since all of the parameters are defined (P == R == T == {}) this should resolve. But again the error:

Error: Encountered type TemplateParameter which we don't know how to emit.

@chrisradek
Copy link
Member Author

@steverice Thanks for bringing that up! This was a scenario I had in mind but clearly missed - working on a fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants