Skip to content
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

[Bug]: precedence/ordering of @@access decorators is unclear #1036

Open
4 tasks done
richardpark-msft opened this issue Jun 18, 2024 · 11 comments · May be fixed by #1606
Open
4 tasks done

[Bug]: precedence/ordering of @@access decorators is unclear #1036

richardpark-msft opened this issue Jun 18, 2024 · 11 comments · May be fixed by #1606
Assignees
Labels
bug Something isn't working lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@richardpark-msft
Copy link
Member

richardpark-msft commented Jun 18, 2024

Describe the bug

I've got a question about @@access, when there are rules that overlap.

In our service we were attempting to make an operation public, only for the scope "go", but internal for everyone else. However, we couldn't do this:

@@access(TestThing, Access.internal);
@@access(TestThing, Access.public, "go");

This generates this type graph:

ModelTestThing
  properties:
    ModelPropertyname
      # extra stuff elided
      data:
         # NOTE that it just gave us all the same access.
         Symbol(@azure-tools/typespec-client-generator-core.access): { }

You can fix this by just ordering them differently:

@@access(TestThing, Access.public, "go");
@@access(TestThing, Access.internal);

This generates this type graph:

ModelTestThing
  properties:
    ModelPropertyname
      # extra stuff elided
      data:
         Symbol(@azure-tools/typespec-client-generator-core.access): { go: "public" }

I'm not entirely sure which behavior is the correct behavior, but I did find it surprising that the more specific directive was overridden by the least specific directive. The ordering of their declarations in the file doesn't seem like it should be a critical factor, especially given how these @@access's could be in separate files altogether.

Including @l0lawrence and @lmazuel in case I've misstated the bug.

Reproduction

Playground Link

Checklist

  • Follow our Code of Conduct
  • Check that this issue is about the Azure libraries for typespec. For bug in the typespec language or core libraries file it in the TypeSpec repo
  • Check that there isn't already an issue that request the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.
@richardpark-msft richardpark-msft added the bug Something isn't working label Jun 18, 2024
@richardpark-msft richardpark-msft changed the title [Bug]: [Bug]: precedence/ordering of @@access decorators is unclear Jun 18, 2024
@richardpark-msft
Copy link
Member Author

@iscai-msft, @lmazuel asked that this be assigned to you specifically.

@iscai-msft
Copy link
Contributor

this seems like a bug, let me take a look at it today

@iscai-msft iscai-msft added lib:tcgc Issues for @azure-tools/typespec-client-generator-core library and removed needs-area labels Jun 18, 2024
@richardpark-msft
Copy link
Member Author

@iscai-msft, just a note, there's another issue that @lmazuel filed about handling CSV lists inside of the 'scope' string as well. The use case was similar to what we were trying to accomplish here.

Issue: #978

@iscai-msft
Copy link
Contributor

@richardpark-msft after looking into it more, we don't want people to set multiple access decorators, because it gets complicated if they conflict with each other. Instead, I think the way around this is adding the ability to do a list of languages, and also adding support for ~ to exclude a language from the list. I'm going to get started on that, and close this issue in favor of #978 if you're ok with that

@richardpark-msft
Copy link
Member Author

@richardpark-msft after looking into it more, we don't want people to set multiple access decorators, because it gets complicated if they conflict with each other. Instead, I think the way around this is adding the ability to do a list of languages, and also adding support for ~ to exclude a language from the list. I'm going to get started on that, and close this issue in favor of #978 if you're ok with that

I think so. If the order is ambiguous then it seems like multiple decorators should cause an outright error otherwise your result might be non-deterministic. What do you think of that?

@iscai-msft
Copy link
Contributor

Yeah that's definitely why we decided originally to not allow multiple instances of either augmentation or direct decorating with @access and @usage. With the pr adding list of scopes, you should be able to do @@access("internal", "python,csharp,go,java,javascript"), which is definitely kind of long. I'm going to start another PR as well in the meantime adding support for ~, but that will require more review just because we have to determine whether we want to add support for tilde

@richardpark-msft
Copy link
Member Author

Just to make sure we're talking about the same thing - in the example I gave I am applying it twice though, and there wasn't (AFAICT) an error. Should there have been? Right now it kind of appears to work, but if the resolution of that is ambiguous, depending on order, it seems like it should fail or provide some sort of warning you're putting yourself in that situation.

(the comma separated list is awesome, but I think the error condition is a separate issue)

@iscai-msft
Copy link
Contributor

Oops I missed this comment. Yeah you're right, there should be a warning raised here. Let me make this a bug and make sure we raise

@iscai-msft iscai-msft removed their assignment Aug 7, 2024
@iscai-msft iscai-msft added this to the [2024] September milestone Aug 7, 2024
@tadelesh
Copy link
Member

tadelesh commented Aug 9, 2024

from our test, this will report a diagnostic. i wonder if it is because the lint rule is not enabled when compiling.

@tadelesh tadelesh self-assigned this Aug 9, 2024
@tadelesh
Copy link
Member

@timotheeguerin in tcgc, i used a core api to report diagnostics (code here). it could work when test, but with the real typespec compile, there is no diagnostic reported. could you help to identify if the usage is wrong?

@markcowl markcowl removed this from the [2024] September milestone Sep 12, 2024
@tadelesh
Copy link
Member

the root cause is previous check does not work on augment decorator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants