You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2023/12/22 11:39:00 UTC

[jira] [Closed] (GROOVY-9960) STC fails to report missing constructor

     [ https://issues.apache.org/jira/browse/GROOVY-9960?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul King closed GROOVY-9960.
-----------------------------

> STC fails to report missing constructor
> ---------------------------------------
>
>                 Key: GROOVY-9960
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9960
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 3.0.7
>            Reporter: Thodoris Sotiropoulos
>            Priority: Major
>
> I have the following (incorrect) program
> {code:java}
> class A {
>   String x;
>   public A(String x) {
>     this.x = x;
>   }
> }
> class B extends A {}
> public class Main {
>   public static void main(String[] args) {
>     B x = new B();
>   }
> }
> {code}
> h3. Actual Behaviour
> The program compiles and when I run it I get the following RuntimeException, because we are missingĀ  a constructor for class `A` that takes no parameters.
> {code:java}
> Exception in thread "main" java.lang.NoSuchMethodError: A: method 'void <init>()' not found
>         at B.<init>(test.groovy)
>         at Main.main(test.groovy:13)
> {code}
> h3. Expected Behaviour
> The program should not compile and the compiler should report an error message, e.g., something similar to the one produced by javac.
> {code:java}
> Main.java:8: error: constructor A in class A cannot be applied to given types;
> class B extends A {}
> ^
>   required: String
>   found: no arguments
>   reason: actual and formal argument lists differ in length
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)