Skip to content

Static type checking errors on maven compile. #344

@dsaita

Description

@dsaita

Hello.
I have a java 7 project that I want to use Groovy in.
I am migrating some classes that I believe should compile but I get errors.
Here is an example:

@CompileStatic
class StaticCompileTest {

    private Number value


    public BigDecimal compiles() {
        return this.value == null || value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(this.value.toString())
    }

    private BigDecimal doesNotCompile() {
        return this.value == null || value instanceof BigDecimal ? value : new BigDecimal(this.value.toString())
    }

    void doesNotCompileToo(Integer other) {
        if (other.compareTo(0) == 0) {
            //
        }
    }

}

[ERROR] return this.value == null || value instanceof BigDecimal ? value : new BigDecimal(this.value.toString())
[ERROR] ^
[ERROR] Groovy:[Static type checking] - Cannot return value of type java.lang.Number on method returning type java.math.BigDecimal
[ERROR]
[ERROR] if (other.compareTo(0) == 0) {
[ERROR] ^^^^^^^^^^^^^^^^^^^
[ERROR] Groovy:[Static type checking] - Reference to method is ambiguous. Cannot choose between [int java.lang.Integer#compareTo(java.lang.Integer), int java.lang.Integer#compareTo(java.lang.Object)]
[ERROR]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions