After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 741465 - Compact abstract classes with abstract methods generates wrong C code
Compact abstract classes with abstract methods generates wrong C code
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.35.x
Other All
: High normal
: 1.0
Assigned To: Daniel Espinosa
Vala maintainers
: 659278 (view as bug list)
Depends on:
Blocks: 792254
 
 
Reported: 2014-12-12 23:55 UTC by pancake
Modified: 2018-03-27 10:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Initial work to provide support for abstract compact classes (6.71 KB, patch)
2018-01-09 02:12 UTC, Daniel Espinosa
none Details | Review
Add support for abstract methods in compact classes (12.41 KB, patch)
2018-01-10 00:15 UTC, Daniel Espinosa
none Details | Review
codegen: Add support for abstract methods/properties in compact classes (13.87 KB, patch)
2018-01-11 21:05 UTC, Rico Tzschichholz
none Details | Review
codegen: Add support for abstract methods/properties in compact classes (13.83 KB, patch)
2018-01-11 21:20 UTC, Rico Tzschichholz
none Details | Review
codegen: Add support for abstract methods/properties in compact classes (13.46 KB, patch)
2018-01-11 23:26 UTC, Rico Tzschichholz
none Details | Review
codegen: Add support for abstract/virtual methods and properties in compact classes (17.21 KB, patch)
2018-01-15 14:28 UTC, Rico Tzschichholz
none Details | Review
codegen: Add support for abstract/virtual methods and properties in compact classes (17.21 KB, patch)
2018-01-15 16:41 UTC, Rico Tzschichholz
committed Details | Review

Description pancake 2014-12-12 23:55:02 UTC
Compact abstract classes generate invalid C code as this example shows:

```
[Compact]
public abstract class Test {
        public abstract void run();
}
void main() {}

```

Compilation output is:

```
minimain.vala.c:32:2: warning: implicit declaration of function 'TEST_GET_CLASS' is invalid in C99 [-Wimplicit-function-declaration]
        TEST_GET_CLASS (self)->run (self);
        ^
minimain.vala.c:32:25: error: member reference type 'int' is not a pointer
        TEST_GET_CLASS (self)->run (self);
        ~~~~~~~~~~~~~~~~~~~~~  ^
1 warning and 1 error generated.
```

By comenting this TEST_GET_CLASS line, the program compiles. but I guess, compact abstract classes cannot work because it depends on GLib machinery. But it would be good to have support for them.
Comment 1 Luca Bruno 2014-12-13 12:34:10 UTC
It's an error to have anything virtual or abstract in compact classes.
Comment 2 Daniel Espinosa 2018-01-05 20:37:10 UTC
(In reply to Luca Bruno from comment #1)
> It's an error to have anything virtual or abstract in compact classes.

So this should be detected by compiler and rise an error.

Features of compact classes are already documented. So we need to close this bug and open a new one related to compiler error reports.

https://bugzilla.gnome.org/show_bug.cgi?id=792254
Comment 3 Daniel Espinosa 2018-01-07 16:03:35 UTC
(In reply to pancake from comment #0)
> Compact abstract classes generate invalid C code as this example shows:
> 
> ```
> [Compact]
> public abstract class Test {
>         public abstract void run();
> }
> void main() {}
> 
> ```
> 
> Compilation output is:
> 
> ```
> minimain.vala.c:32:2: warning: implicit declaration of function
> 'TEST_GET_CLASS' is invalid in C99 [-Wimplicit-function-declaration]
>         TEST_GET_CLASS (self)->run (self);
>         ^
> minimain.vala.c:32:25: error: member reference type 'int' is not a pointer
>         TEST_GET_CLASS (self)->run (self);
>         ~~~~~~~~~~~~~~~~~~~~~  ^
> 1 warning and 1 error generated.
> ```
> 
> By comenting this TEST_GET_CLASS line, the program compiles. but I guess,
> compact abstract classes cannot work because it depends on GLib machinery.
> But it would be good to have support for them.

Above C generated code is:

typedef _Test Test;
struct _Test {
	int dummy;
};
static gboolean
test_real_run (Test* self)
{
	gboolean _tmp0_ = FALSE;
	g_critical ("Type `%s' does not implement abstract method `test_run'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return _tmp0_;
}


gboolean
test_run (Test* self)
{
	g_return_val_if_fail (self != NULL, FALSE);
	return TEST_GET_CLASS (self)->run (self);
}


I found:

a) Test class is never registered in the GType system, as a GBoxed (like GDate), so it is hard to use as a property in GObject classes

b) If a) is expected, test_real_run() should avoid to use G_TYPE_FROM_INSTANCE()

c) Method test_run() should replace:

return TEST_GET_CLASS (self)->run (self);

with:

return self->run (self);
Comment 4 Daniel Espinosa 2018-01-09 02:12:55 UTC
Created attachment 366527 [details] [review]
Initial work to provide support for abstract compact classes

Abstract compact classes are required by GLib VAPI in GSource, as it is an abstract compact class with abstract methods.

So Vala should allow to generate these kind of classes, allows implement its virtual methods and provide print error messages methods for unimplemented classes, like the ones of GInterfaces.

I've just don't find a way to add virtual methods to a compact class declarations, at C generated code. This is a WIP any advice on how to do so, is welcome.

This patch just shows advances but no make test pass yet.
Comment 5 Daniel Espinosa 2018-01-10 00:15:11 UTC
Created attachment 366582 [details] [review]
Add support for abstract methods in compact classes

Vala: Add support for abstract methods in compact classes
    
    Adds support to declare an abstract compact class with
    abstract methods.
    
    Methods should be implemented by derived classes.
    
    Derived classes are compact class too.
    
    Added initialization code to implement abstract classes
    to printout warnings on unimplemented methods.
    
    Derived classes, can override base compact classes' abstract
    methods.
    
    No new fiels are allowed, as always.
    
    Abstract properties should be possible, but need to be fixed. So,
    for now, an error is rised if a property is defined.
Comment 6 Rico Tzschichholz 2018-01-11 21:05:15 UTC
Created attachment 366685 [details] [review]
codegen: Add support for abstract methods/properties in compact classes
Comment 7 Rico Tzschichholz 2018-01-11 21:07:11 UTC
I have cleaned it up a bit and fixed the properties support.

Still needs some more verifying.
Comment 8 Rico Tzschichholz 2018-01-11 21:20:54 UTC
Created attachment 366686 [details] [review]
codegen: Add support for abstract methods/properties in compact classes
Comment 9 Daniel Espinosa 2018-01-11 23:21:38 UTC
Review of attachment 366686 [details] [review]:

It's Ok for me.

Thanks to fix abstract properties in compact classes. Was really hard to me to find where I need to change the code for them.
Comment 10 Rico Tzschichholz 2018-01-11 23:26:16 UTC
Created attachment 366691 [details] [review]
codegen: Add support for abstract methods/properties in compact classes
Comment 11 Rico Tzschichholz 2018-01-11 23:27:34 UTC
Fixed regression with found with libgee test-suite.
Comment 12 Rico Tzschichholz 2018-01-15 14:28:38 UTC
Created attachment 366834 [details] [review]
codegen: Add support for abstract/virtual methods and properties in compact classes

Based on patch by Daniel Espinosa
Comment 13 Daniel Espinosa 2018-01-15 14:43:04 UTC
(In reply to Rico Tzschichholz from comment #12)
> Created attachment 366834 [details] [review] [review]
> codegen: Add support for abstract/virtual methods and properties in compact
> classes
> 
> Based on patch by Daniel Espinosa

I think you should prepare at least two commits:

* One with my initital work *as is*
* One with all your fixes and additions

This is the way I do with my contributors. In the history they will see their names for they work and then authors can push fixes, minor corrections or features additions on the original work. Just push all at the same time, when you are satisfied with the final result.

Why I say this? because in the pass you have pushed my work with your own additions while you don't take credit on your work. With this all will be satisfied and credit their work.
Comment 14 Rico Tzschichholz 2018-01-15 15:14:16 UTC
@daniel: I see, although I don't want to push something while reverting parts of it in the next commit. I guess you noticed that I ran into a few issues with your initial work. While abstract/virtual methods are very entangled it is hard to split them up properly.

If you insist I can set you as author and mention my involvement in the commit message?

Note that such discussions up front would be easier over IRC.
Comment 15 Rico Tzschichholz 2018-01-15 15:50:15 UTC
@daniel: So it would be great if you start joining the #vala irc channel.
Comment 16 Rico Tzschichholz 2018-01-15 16:41:46 UTC
Created attachment 366847 [details] [review]
codegen: Add support for abstract/virtual methods and properties in compact classes

Reworked and extened by Rico Tzschichholz
Comment 17 Rico Tzschichholz 2018-01-15 19:38:45 UTC
Attachment 366847 [details] pushed as 28b4f45 - codegen: Add support for abstract/virtual methods and properties in compact classes
Comment 18 Rico Tzschichholz 2018-03-27 10:16:52 UTC
*** Bug 659278 has been marked as a duplicate of this bug. ***