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

Fix warning on using Channel.select #8454

Closed

Conversation

asterite
Copy link
Member

@asterite asterite commented Nov 7, 2019

@jkthorne
Copy link
Contributor

jkthorne commented Nov 7, 2019

should there be a test for this?

@bcardiff
Copy link
Member

bcardiff commented Nov 7, 2019

If deprecated code is not tested it is not guaranteed to stay working.

I prefer a CI with warnings rather than untested deprecated methods. But If I'm the only one who thinks that way, we can go ahead.

@asterite
Copy link
Member Author

asterite commented Nov 7, 2019

If deprecated code is not tested it is not guaranteed to stay working

Oh, I didn't know that was the reason it was kept.

@asterite asterite closed this Nov 7, 2019
@asterite asterite deleted the warning/channel-select branch November 7, 2019 22:18
@straight-shoota
Copy link
Member

Maybe we could consider adding comments for such specs that are explicitly meant to test deprecated behaviour. Otherwise I expect we will eventually get more "fix warning" PRs in the future.

@straight-shoota
Copy link
Member

straight-shoota commented Nov 7, 2019

I'll award bonus points for having a mechanism for designating a spec as testing a specific deprecated method and disabling deprecation warnings for this method inside the spec's body.

@bcardiff
Copy link
Member

bcardiff commented Nov 7, 2019

Definitely. But is either be

  • a new keyword to be applied in a given lexical scope (as checked in [WIP] Arithmetic with Overflow #6223) or
  • an annotation that could express only for the whole method level. (not useful in specs)
  • magic comments (I don't like it)

So, something like this?

pragma(allow_deprecated: true) { expr }

@asterite
Copy link
Member Author

asterite commented Nov 7, 2019

I don't think this is worth our efforts. After all it's just a warning.

@straight-shoota
Copy link
Member

I agree. It was just an idea that popped into my head but should be filed under "in case you're bored and have nothing else to do".

@straight-shoota
Copy link
Member

I don't know why I kept thinking about this. But it bugged me. And I think this could actually be very simple to implement. Because this really only affects specs and deprecated methods should only be called directly in the spec body, a naive static filter should be enough.

require "spec"

@[Deprecated]
def deprecated
end

it "test deprecated method" do
  deprecated
end

This is the warning:

In deprecation_spec.cr:8:3

 8 | deprecated
     ^---------
Warning: Deprecated top-level deprecated.

crystal spec, after compiling the program reports the warnings. These could simply be filtered based on file and line number. If it's in a spec file and maybe has some kind of annotation naming the deprecated method that should be suppressed.

Obviously this won't work if the deprecated method is called indirectly. But that should be avoided anyway because it would mean the deprecated method is used in some code other than specs.

@asterite
Copy link
Member Author

asterite commented Nov 9, 2019

The warnings are reported during compilation, not at runtime. I don't know if you took that into account.

@straight-shoota
Copy link
Member

Yes. Runtime doesn't matter. The spec command knows about the warnings an has the source code. So it can easily lookup the warning location in the source and check whether there is for example a comment designating this spec as testing a deprecated method.

@RX14
Copy link
Contributor

RX14 commented Nov 16, 2019

The warnings code already has a check for which directories to ignore warnings in (lib). It would be trivial to expose that on the crystal commandline, and add spec.

@straight-shoota
Copy link
Member

This off-topic discussion should be continued in #8477

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.

5 participants