[ 
https://issues.apache.org/jira/browse/GROOVY-11688?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King resolved GROOVY-11688.
--------------------------------
    Fix Version/s: 5.0.0-beta-2
       Resolution: Fixed

Proposed PR merged.

> Potential minor improvement to STC error message
> ------------------------------------------------
>
>                 Key: GROOVY-11688
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11688
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>             Fix For: 5.0.0-beta-2
>
>
> Currently for named args we report the error on the "whole map" of args 
> rather than a specific one if a problem is found for a specific one.
> {code:groovy}
> import groovy.transform.*
> @Immutable(copyWith = true)
> class DoctorWho {
>     String first, last
>     Integer number
> }
> @TypeChecked
> def method() {
>     def dr4 = new DoctorWho(first: 'Tom', last: 'Baker', number: 4, born: 
> 1934)
>     def dr6 = dr4.copyWith(first: 'Colin', number: 'six')
>     println dr4
>     println dr6
> }
> method()
> {code}
> We see an error like this:
> {noformat}
> DrWhoScript.groovy: 11: [Static type checking] - unexpected named arg: born
>  @ line 11, column 29.
>        def dr4 = new DoctorWho(first: 'Tom', last: 'Baker', number: 4, born: 
> 1934)
>                                ^
> DrWhoScript.groovy: 12: [Static type checking] - argument for named param 
> 'number' has type 'java.lang.String' but expected 'java.lang.Integer'.
>  @ line 12, column 28.
>        def dr6 = dr4.copyWith(first: 'Colin', number: 'six')
>                               ^
> 2 errors
> {noformat}
> This issue proposes it changes to this:
> {noformat}
> DrWhoScript.groovy: 11: [Static type checking] - unexpected named arg: born
>  @ line 11, column 69.
>    m', last: 'Baker', number: 4, born: 1934
>                                  ^
> DrWhoScript.groovy: 12: [Static type checking] - argument for named param 
> 'number' has type 'java.lang.String' but expected 'java.lang.Integer'.
>  @ line 12, column 44.
>     dr4.copyWith(first: 'Colin', number: 's
>                                  ^
> 2 errors
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to