GNOME Bugzilla – Bug 646713
PATCH: Implement alias functionality for 'using' directive
Last modified: 2018-05-22 13:59:49 UTC
Created attachment 185109 [details] [review] PATCH: Implement alias functionality for 'using' directive Vala currently (0.12.0) has no way to disambiguate symbol references in case of matches from multiple 'using' statements. I've implemented the alias functionality missing from 'using'. It took 3 tries before I found a way that worked and didn't upset the existing code too much. As Vala tries to follow C#, I've done it the C# way. According to the C# language spec 9.3.2, an alias can be used to disambiguate the case which at the moment gives an "ambiguous reference" error. I've added error messages that suggest the using directives that the user can insert to resolve the issue. For example, compiling the following code with this patch: using Gee; public void main() { Queue queue = new LinkedList<Object>(); } gives the following error message: bug.vala:4.2-4.6: error: `Queue' is an ambiguous reference; add one of these aliases to resolve: using Queue = GLib.Queue; using Queue = Gee.Queue; Queue queue = new LinkedList<Object>(); ^^^^^ Adding in 'using Queue = Gee.Queue;' fixes the problem. This code builds now: using Gee; using Queue = Gee.Queue; public void main() { Queue queue = new LinkedList<Object>(); } I've tried to follow the existing style. I checked all the code related to existing 'using' functionality -- I hope I got it right. I've added a new test case, and the existing test cases pass. If this patch isn't okay, I can make changes and reissue. Jim
Even without "using Queue = Gee.Queue", you can still just use "Gee.Queue" in your code, just like you can without any using statement at all.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/189.