Re: Type inference runtime error

Paul King <[email protected]>
Newsgroups gmane.comp.lang.groovy.user
Message-ID <CAMbkE7T90JRBQK3ygV7annie=SLi72L09xGTy9Y2a5nC9EaTdA@mail.gmail.com>
The key aspect for that example is in the preceding paragraph "When
code is annotated with @TypeChecked".

If you had those three lines in a script called Upper.groovy, you could try:

> groovy --compile-static Upper.groovy

Or in the groovyConsole, you could try something like this:

@groovy.transform.TypeChecked // or CompileStatic
static main(args) {
    def message = 'Welcome to Groovy!'
    println message.toUpperCase()
    println message.upper()
}

You should see the compile time error. The runtime error is the
expected behavior without type checking in play.

Cheers, Paul.

On Thu, Jun 16, 2022 at 5:28 AM Henry <[email protected]> wrote:
>
> Hi
>
> In the example of the documentation
> https://groovy-lang.org/semantics.html#type-inference the callout number
> 3 states 'calling |upper| will fail at compile time'. But when I run
> those three lines of code in GroovyConsole I get
> groovy.lang.MissingMethodException which is a runtime exception.
>
> So shouldn't it say '... will fail at runtime'?
>
> Thanks.
>
> Henry
>
>
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.