Skip to content

Operations referenced from an instantiated template interface do not get cached correctly #1834

Description

@daviwil

I randomly walked into this issue recently and it seems pretty serious, definitely affects Azure.Core mainline scenarios around ResourceOperations<Traits> interface.

Here's the repro:

  • Define a templated interface which contains an operation that spreads the template parameter directly into the parameter list
  • Use aliases to create two instances of the same interface with different model types for the template parameter
  • Define operations which reach through the two aliases to use the contained operation signature
  • The second operation will have the same parameters spread in as the first

This example should help clarify it:

Playground repro

import "@typespec/http";

using TypeSpec.Http;

model Foo {
  name: string;
}

model ExtraParams {
  @path
  classId: string;

  @path
  assignmentId: string;
}

interface StandardOps<TExtraParams extends object = {}> {
  op Get<TResource>(...TExtraParams): TResource;
}

alias OpsNoExtraParams = StandardOps;
alias OpsByClassIdAssignmentId = StandardOps<ExtraParams>;

@route("foo")
op get is OpsNoExtraParams.Get<Foo>;

@route("foo/classes/{classId}/assignments/{assignmentId}")
op getWithParams is OpsByClassIdAssignmentId.Get<Foo>;

The @route decorator here complains that classId and assignmentId are not found in the parameter list of the operation. If you check the getWithParams operation in the type graph, you'll see that it is missing those two parameters when it should have them from the OpsByClassIdAssignmentId's interface instantiation.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions