Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0-rc-1
-
Fix Version/s: 2.0-rc-3
-
Component/s: Static Type Checker
-
Labels:None
-
Number of attachments :
Description
@TypeChecked
class StaticGroovy2 {
def bar() {
def foo = [new Date(), 1, new C()]
foo.add( 2 ) // Compiles
foo.add( new Date() )
foo.add( new C() )
foo = [new Date(), 1]
foo.add( 2 ) // Does not compile
}
}
class C{
}
This code fails to compile on the last line foo.add(2) with the error:
Groovy:[Static type checking] - Cannot find matching method
java.util.List#add(int)
Just to amend the description, there are two issues in one, here:
Using
def foo = [new Date(), 1] foo.add( 2 )we shouldn't throw any error. Second, this should throw an error, according to our flow typing implementation:
def foo = [new Date()] foo.add(1)as well as
def foo = [1] foo = [new Date()] foo.add(1)So basically, there's only one problem to be fixed here, which is the error with the type inference engine not recognizing that an integer may be added to the list.