[ 
https://issues.apache.org/jira/browse/GROOVY-11688?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17955540#comment-17955540
 ] 

ASF GitHub Bot commented on GROOVY-11688:
-----------------------------------------

eric-milles commented on PR #2244:
URL: https://github.com/apache/groovy/pull/2244#issuecomment-2927723778

   I agree it is better to have the error located on the specific named 
argument instead of the start of the argument list.




> 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
>
> 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