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 760031 - vala allows access to protected constructors
vala allows access to protected constructors
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2015-12-31 17:31 UTC by Timm Bäder
Modified: 2016-10-08 20:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Reproducer (163 bytes, text/x-vala)
2015-12-31 17:31 UTC, Timm Bäder
  Details
Deny access to protected constructors (1.14 KB, patch)
2015-12-31 17:32 UTC, Timm Bäder
none Details | Review
Updated patch (1.14 KB, patch)
2016-02-03 01:52 UTC, Ben
none Details | Review
Deny access to protected constructors (2.33 KB, patch)
2016-10-08 19:15 UTC, Rico Tzschichholz
committed Details | Review

Description Timm Bäder 2015-12-31 17:31:53 UTC
Created attachment 318081 [details]
Reproducer

See attached reproducer. valac doesn't complain if one calls a protected constructor from outside the class or a child class.
Comment 1 Timm Bäder 2015-12-31 17:32:48 UTC
Created attachment 318082 [details] [review]
Deny access to protected constructors
Comment 2 Ben 2016-02-03 01:52:03 UTC
Created attachment 320302 [details] [review]
Updated patch
Comment 3 Al Thomas 2016-09-11 15:20:32 UTC
Review of attachment 318082 [details] [review]:

Patch no longer applies against master and a new patch has been supplied
Comment 4 Al Thomas 2016-09-11 15:34:48 UTC
Review of attachment 320302 [details] [review]:

Patch works against reproducer. The error message is:
test20.vala:15.11-15.22: error: Access to private member `Foobar.new' denied

I think this would be better if it was:
test20.vala:15.11-15.22: error: Access to protected member `Foobar.new' denied

There is already an access to protected member denied elsewhere in libvala. So I think it should be here as well to be consistent.

Now that tests for invalid code are supported ( https://git.gnome.org/browse/vala/commit/?id=2f924f63f6d7bcaa3df13e2ee9d365b25b5a00b4 ) I think a test case should be with the patch.
See https://git.gnome.org/browse/vala/commit/?id=97de315bb903014975347949e513421599e76c9c for an example.

The test case can be reduced significantly. All you need is:

class Foobar {
  protected Foobar(){}
}

void main () {
  new Foobar();
}
Comment 5 Rico Tzschichholz 2016-10-08 19:15:35 UTC
Created attachment 337252 [details] [review]
Deny access to protected constructors
Comment 6 Rico Tzschichholz 2016-10-08 20:16:18 UTC
Attachment 337252 [details] pushed as 588c00e - Deny access to protected constructors