Paul King created GROOVY-11688:
----------------------------------

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


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