Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build.gradle file, task using << notation, intellij warns: "Cannot infer argument type"

I'm new to groovy and gradle and was wondering whether someone knew why my scriplet wasn't working (edit actually it does work but the warning still appears). This section is taken out of the build.gradle script and intellij highlights this and complains that it: "Cannot infer argument types". any help would be nice :)

task hellofun << {
    [silly:'billy'].each { k, v ->
        println "$k=$v"
    }
}

EDIT: I have submitted a bug request informing Intellij of this problem

EDIT: apparently this is a known bug I'll update this once the bug is fixed

like image 440
coderatchet Avatar asked Dec 12 '13 07:12

coderatchet


3 Answers

If you are willing to disable the Groovy > Assignment Issues > Incompatible type assignments inspection, the warning goes away.

like image 139
pmcollins Avatar answered Nov 20 '22 03:11

pmcollins


In a highly dynamically typed language such as groovy where names and symbols are resolved in arbitrary ways It would be quite difficult to determine the validity of any statement ahead of time without running the program. even running the program would theoretically not divulge all possible permutations of input that may change the runtime validity of a statement.

I applaud intellij's attempt at this hard problem and can live with a few incorrect syntax warnings here and there.

like image 38
coderatchet Avatar answered Nov 20 '22 03:11

coderatchet


Untill the IntelliJ bug is fixed, there is a workaround: use doFirst instead of <<.

task hellofun() {
  doFirst {
    [silly:'billy'].each { k, v ->
      println "$k=$v"
    }
  }
}

Thanks for submitting the bug :)

like image 2
Odinodin Avatar answered Nov 20 '22 01:11

Odinodin