Crystal: [FEATURE] "No overload matches" output confusing

Created on 13 Sep 2019  路  2Comments  路  Source: crystal-lang/crystal

Problem:

  • It's hard to pick which argument has the wrong type with lots of overloads or lots arguments.

Example:

Error: no overload matches 'Sodium::Cipher::Aead::Xchacha20Poly1305Ietf#decrypt_detached'
 with types Slice(UInt8), nonce: Sodium::Nonce, mac: Slice(UInt8), additional: String

Overloads are:
 - Sodium::Cipher::Aead::Xchacha20Poly1305Ietf#decrypt_detached(src : Bytes,
 - - dst : Bytes | ::Nil = nil, *, nonce : Nonce, 
 - - mac : Bytes, additional : Bytes | ::Nil = nil)
 - Sodium::Cipher::Aead::Chalsa#decrypt_detached(data, 
 - - dst : Bytes | ::Nil = nil, *, 
 - - mac : Bytes | ::Nil = nil, additional = nil)

Feature request:

  • Colorize the output for matching and nonmatching types to quickly see which types are incorrect.

Most helpful comment

Colorize could help, but only when color is supported (for example on a TTY).

A good improvement would probably already be when we get the types at call site and the overloads formatted in the same way, using a proper crystal format style. This would make it easier to read the signatures and help compare them.

Additionally, it would be super great if matching arguments could be lined up similarly. This should work great for short signatures. But as soon as there are many arguments which span multiple lines and optional arguments not present everywhere, this becomes super complicated.

Example for a relatively simple set of overloads:

Call:
- foo(String,                             c: Nil)

Overloads are:
 - foo(a : String,         b : Int32 = 0, c : Bool = true)
 - foo(a : String,         b : Float64,   c : Bool = false)
 - foo(a : String,         b : Int64,     c : Bool)
 - foo(a : Time::Location, b,             c : Nil)

All 2 comments

Colorize could help, but only when color is supported (for example on a TTY).

A good improvement would probably already be when we get the types at call site and the overloads formatted in the same way, using a proper crystal format style. This would make it easier to read the signatures and help compare them.

Additionally, it would be super great if matching arguments could be lined up similarly. This should work great for short signatures. But as soon as there are many arguments which span multiple lines and optional arguments not present everywhere, this becomes super complicated.

Example for a relatively simple set of overloads:

Call:
- foo(String,                             c: Nil)

Overloads are:
 - foo(a : String,         b : Int32 = 0, c : Bool = true)
 - foo(a : String,         b : Float64,   c : Bool = false)
 - foo(a : String,         b : Int64,     c : Bool)
 - foo(a : Time::Location, b,             c : Nil)

The class and method name take a lot of horizontal space. Show it once?
Sodium::Cipher::Aead::Xchacha20Poly1305Ietf#decrypt_detached

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RX14 picture RX14  路  3Comments

cjgajard picture cjgajard  路  3Comments

ArthurZ picture ArthurZ  路  3Comments

nabeelomer picture nabeelomer  路  3Comments

lbguilherme picture lbguilherme  路  3Comments