Crystal: developers should not receive deprecation warnings about things in the core language.

Created on 31 Dec 2019  路  7Comments  路  Source: crystal-lang/crystal

Premise:

Compiler warnings are instructions to the developer about failings in their application that should be addressed.

Compiler warnings should NOT warn the developer about deprecations the language creators haven't gotten around to addressing yet.

Problem:

I just built my app and received this warning:

In /usr/local/Cellar/crystal/0.32.1/src/uri/encoding.cr:116:3

 116 | def self.unescape(string : String, plus_to_space = false)
       ^-------
Warning: Deprecated URI.unescape. Use .decode or .decode_www_form instead

A total of 1 warnings were found.

This is not a problem in _my_ software. Developers like me, should receive warnings about things we can address in our apps, but not about failings in the core language.

I'm not sure if this is actually possible, but it'd be awfully nice.

Crystal 0.32.1 (2019-12-18)

LLVM: 9.0.0
Default target: x86_64-apple-macosx

Most helpful comment

Yes but the error message is pointing to the method definition, not the callsite.

This is a bug.

All 7 comments

Are you sure this isn't an issue in your app or a shard that your app requires?

I built the compiler with warnings and didn't see any.

This is a deprecation warning.

Something is calling the deprecated URI.unescape, either your app or a shard does, that will break if a future crystal release, and it should be fixed.

Yes but the error message is pointing to the method definition, not the callsite.

This is a bug.

@ysbaddaden & @Blacksmoke16

entirely possible (maybe even probable), but as @RX14 pointed out, the error message is pointing to the wrong place which led me to think it was something in encoding.cr that was having the issue not something in my code.

I _think_ the right thing to do here is to kill this ticket and create a new, more accurate one, about the warning pointing to the wrong place. Yes?

That's odd, seems to work fine here:

In src/view_helpers.cr:15:24

 15 | google_search = URI.escape(url.name + " poster", true)
                          ^-----
Warning: Deprecated URI.escape. Use .encode or .encode_www_form instead

So yeah I'd file a new bug for it...with a simplified reproducible test case :)

Building

# foo.cr
require "uri"

URI.escape("foo")

leads to

$ ./bin/crystal build foo.cr
In foo.cr:3:5

 3 | URI.escape("foo")
         ^-----
Warning: Deprecated URI.escape. Use .encode or .encode_www_form instead

In src/uri/encoding.cr:174:3

 174 | def self.escape(string : String, space_to_plus = false)
       ^-----
Warning: Deprecated URI.escape. Use .encode or .encode_www_form instead

A total of 2 warnings were found.

The issue is that the compiler generates a method to introduce the default argument.


A minimalistic example is:

@[Deprecated]
def m(arg = 0)
end

m
$ ./bin/crystal build foo.cr 
In foo.cr:5:1

 5 | m
     ^
Warning: Deprecated top-level m.

In foo.cr:2:1

 2 | def m(arg = 0)
     ^
Warning: Deprecated top-level m.

A total of 2 warnings were found.

Since it is equivalent to

@[Deprecated]
def m
  m(0)
end

@[Deprecated]
def m(arg)
end

m

Hence, the two calls m and m(0) to depreceated method.

To fix this the Def AST needs:

As a workaround,

  1. expand manually the default args, or
  2. ignore std-lib in the warnings path crystal build --exclude-warnings=/usr/local/Cellar/crystal/0.32.1/src foo.cr

@bcardiff The explanation seems to fit, but what's the original cause for URI.escape being called at all? In your example the compiler warns about a deprecated call in foo.cr:3:5 which calls the method with default argument and this autogenerated method calls the declared method, causing the second deprecation warning.

In the OP, there is not primary deprecation warning. Any idea what could be the cause for this? @masukomi I'm assuming you've posted all deprecation warnings? Could you share the code that triggered this?

Was this page helpful?
0 / 5 - 0 ratings