You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefanos Chaliasos (Jira)" <ji...@apache.org> on 2022/06/28 22:06:00 UTC
[jira] [Created] (GROOVY-10670) Cannot resolve type in the presence of use-site contravariance
| ![](cid:jira-generated-image-avatar-781e97dc-c48b-4713-9fd2-b05e79f93ec7) |
[Stefanos
Chaliasos](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=schaliasos)
**created** an issue
---|---
|
---
| [Groovy](https://issues.apache.org/jira/browse/GROOVY) / [![Bug](cid:jira-
generated-image-
avatar-5350ce59-c182-43cf-8b46-d4690fc8b6d9)](https://issues.apache.org/jira/browse/GROOVY-10670)
[GROOVY-10670](https://issues.apache.org/jira/browse/GROOVY-10670)
---
[Cannot resolve type in the presence of use-site
contravariance](https://issues.apache.org/jira/browse/GROOVY-10670)
| Issue Type: | ![Bug](cid:jira-generated-image-
avatar-5350ce59-c182-43cf-8b46-d4690fc8b6d9) Bug
---|---
Affects Versions: | 4.0.3
Assignee: | Unassigned
Components: | Static compilation, Static Type Checker
Created: | 28/Jun/22 22:05
Priority: | ![Major](cid:jira-generated-image-static-
major-a843e56d-fe1c-407b-90f1-a650be8380ff) Major
Reporter: | [Stefanos
Chaliasos](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=schaliasos)
|
I have the following Groovy program.
class Main {
static final Bar<? super Short> bar = new Bar<Short>((Short) -94)
static final short foo = Main.bar.x
}
class Bar<P> {
public final P x
public Bar(P x) {
this.x = x
}
}
### Actual Behavior
The program does not compile, and I get the following error.
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Main.groovy: 5: [Static type checking] - Cannot assign value of type java.lang.Object to variable of type short
@ line 5, column 28.
static final short foo = Main.bar.x
^
1 error
### Expected Behavior
Compile successfully.
### Comment
Note that the equivalent Java program is accepted by javac.
Tested against 4.0.3 and master (commit:
2e82c9f5bd6201ed4724b26714275f4cef9df6e8).
---
| | [ ![Add Comment](cid:jira-generated-image-static-comment-
icon-908d4e41-9a97-4a5d-a521-1bbf75b6c908)
](https://issues.apache.org/jira/browse/GROOVY-10670#add-comment "Add
Comment") | [Add
Comment](https://issues.apache.org/jira/browse/GROOVY-10670#add-comment "Add
Comment")
---|---
| This message was sent by Atlassian Jira (v8.20.10#820010-sha1:ace47f9) | |
![Atlassian logo](https://issues.apache.org/jira/images/mail/atlassian-email-
logo.png)
---