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 615830 - Vala must always check generic type parameters.
Vala must always check generic type parameters.
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Generics
unspecified
Other Linux
: Urgent blocker
: ---
Assigned To: Vala maintainers
Vala maintainers
wrong-code
: 626778 638029 (view as bug list)
Depends on:
Blocks: 638029 641418
 
 
Reported: 2010-04-15 10:38 UTC by Luca Bruno
Modified: 2016-09-28 07:20 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Enhance checking of generic type arguments. (2.79 KB, patch)
2010-09-24 15:45 UTC, Luca Bruno
none Details | Review
Enhance checking of generic type arguments. (2.60 KB, patch)
2010-09-25 18:54 UTC, Luca Bruno
none Details | Review
Enhance checking of generic type arguments (3.46 KB, patch)
2010-11-28 10:22 UTC, Luca Bruno
reviewed Details | Review
Improve compatibility check for generic type arguments (2.65 KB, patch)
2011-08-24 09:59 UTC, Luca Bruno
reviewed Details | Review
fixes this bug (3.42 KB, patch)
2016-08-08 17:43 UTC, Matthias Berndt
none Details | Review
bugfix + testcase (4.58 KB, patch)
2016-08-10 22:08 UTC, Matthias Berndt
none Details | Review
bugfix + testcase (4.79 KB, patch)
2016-08-11 10:07 UTC, Matthias Berndt
reviewed Details | Review
Updated patch (4.30 KB, patch)
2016-09-12 20:10 UTC, Jürg Billeter
reviewed Details | Review
Updated patch (5.30 KB, patch)
2016-09-20 22:51 UTC, Matthias Berndt
none Details | Review
Updated patch (5.75 KB, patch)
2016-09-20 23:00 UTC, Matthias Berndt
none Details | Review
Updated patch (5.75 KB, patch)
2016-09-20 23:01 UTC, Matthias Berndt
none Details | Review
patch (5.73 KB, patch)
2016-09-25 17:01 UTC, Matthias Berndt
none Details | Review
patch (5.73 KB, patch)
2016-09-25 18:00 UTC, Matthias Berndt
none Details | Review
patch (5.73 KB, patch)
2016-09-25 18:04 UTC, Matthias Berndt
committed Details | Review

Description Luca Bruno 2010-04-15 10:38:15 UTC
Hello,
example:
Gee.List<string> l = new Gee.LinkedList<int>();

This reports no errors, but it makes your application crash of course. Vala must check compatibility between generic type parameters. This doesn't happen if the class is the same, e.g. Gee.LinkedList = Gee.LinkedList.
Comment 1 zarevucky.jiri 2010-08-12 20:52:52 UTC
*** Bug 626778 has been marked as a duplicate of this bug. ***
Comment 2 Luca Bruno 2010-09-24 15:45:28 UTC
Created attachment 171039 [details] [review]
Enhance checking of generic type arguments.

Fixes bug 615830.
Comment 3 zarevucky.jiri 2010-09-24 22:10:41 UTC
I've looked at the path and I believe it isn't entirely correct. Two generic types are compatible only if the type arguments are exact match. For example, you can't pass List<Widget> as List<Object>, because that would mean you could add some non-widget to a list of widgets.
Requiring exact match is inflexible, but Vala is missing syntax that could solve this problem.
Comment 4 Luca Bruno 2010-09-25 18:54:55 UTC
Created attachment 171103 [details] [review]
Enhance checking of generic type arguments.

Fixes bug 615830.

You're totally right, I've missed that. New patch checks for equality instead of compatibility.
Comment 5 zarevucky.jiri 2010-09-25 19:06:52 UTC
It should be noted that this patch will probably break some code. There are many valid usages that won't pass this check, because as I said, the syntax to allow more flexible typing is missing in Vala.
Comment 6 Luca Bruno 2010-11-28 10:22:36 UTC
Created attachment 175405 [details] [review]
Enhance checking of generic type arguments

This will check for nested generics as well.
Comment 7 Luca Bruno 2010-12-27 11:14:23 UTC
*** Bug 638029 has been marked as a duplicate of this bug. ***
Comment 8 Luca Bruno 2011-08-24 09:59:11 UTC
Created attachment 194562 [details] [review]
Improve compatibility check for generic type arguments

Check for generic type arguments compatibility when the target type
is a subtype of this. Also enforce ownership of generic type arguments
to match target generic type arguments to avoid memory management issues.

Partially fixes 615830.
Comment 9 Matthias Berndt 2016-08-08 17:43:36 UTC
Created attachment 332950 [details] [review]
fixes this bug

Hey guys,

I noticed this bug independently, fixed it and then found this bug report. I'm attaching a patch, it would be great if somebody could take a look…

Cheers,
Matthias
Comment 10 Evan Nemerson 2016-08-10 04:44:32 UTC
Review of attachment 332950 [details] [review]:

Causes an error when compiling SQLHeavy (https://github.com/nemequ/sqlheavy):

  • #0 raise
    from /lib64/libc.so.6
  • #1 abort
    from /lib64/libc.so.6
  • #2 g_assertion_message
  • #3 g_assertion_message_expr
    at /home/nemequ/local/src/gnome/glib/glib/gtestutils.c line 2452
  • #4 vala_array_list_real_get
    at arraylist.c line 383
  • #5 vala_data_type_real_compatible
    at valadatatype.c line 2525
  • #6 vala_semantic_analyzer_check_argument
    at valasemanticanalyzer.c line 3695
  • #7 vala_semantic_analyzer_check_arguments
    at valasemanticanalyzer.c line 3349
  • #8 vala_method_call_real_check
    at valamethodcall.c line 4711
  • #9 vala_assignment_real_check
    at valaassignment.c line 2615
  • #10 vala_expression_statement_real_check
    at valaexpressionstatement.c line 366
  • #11 vala_block_real_check
    at valablock.c line 2037
  • #12 vala_if_statement_real_check
    at valaifstatement.c line 1529
  • #13 vala_block_real_check
    at valablock.c line 2037
  • #14 vala_if_statement_real_check
    at valaifstatement.c line 1539
  • #15 vala_block_real_check
    at valablock.c line 2037
  • #16 vala_if_statement_real_check
    at valaifstatement.c line 1529
  • #17 vala_block_real_check
    at valablock.c line 2037
  • #18 vala_property_accessor_real_check
    at valapropertyaccessor.c line 1283
  • #19 vala_property_real_check
    at valaproperty.c line 1771
  • #20 vala_member_access_real_check
    at valamemberaccess.c line 3910
  • #21 vala_member_access_real_check
    at valamemberaccess.c line 2277
  • #22 vala_method_call_real_check
    at valamethodcall.c line 2020
  • #23 vala_expression_statement_real_check
    at valaexpressionstatement.c line 366
  • #24 vala_block_real_check
    at valablock.c line 2037
  • #25 vala_method_real_check
    at valamethod.c line 4487
  • #26 vala_class_real_check
    at valaclass.c line 4079
  • #27 vala_object_type_real_check
    at valaobjecttype.c line 761
  • #28 vala_parameter_real_check
    at valaparameter.c line 987
  • #29 vala_delegate_real_check
    at valadelegate.c line 1822
  • #30 vala_field_real_check
    at valafield.c line 869
  • #31 vala_class_real_check
    at valaclass.c line 3989
  • #32 vala_object_type_real_check
    at valaobjecttype.c line 761
  • #33 vala_object_type_real_check
    at valaobjecttype.c line 871
  • #34 vala_field_real_check
    at valafield.c line 869
  • #35 vala_class_real_check
    at valaclass.c line 3989
  • #36 vala_object_type_real_check
    at valaobjecttype.c line 761
  • #37 vala_field_real_check
    at valafield.c line 869
  • #38 vala_class_real_check
    at valaclass.c line 3989
  • #39 vala_source_file_check
    at valasourcefile.c line 1343
  • #40 vala_code_context_accept
    at valacodecontext.c line 1217
  • #41 vala_semantic_analyzer_analyze
    at valasemanticanalyzer.c line 2085
  • #42 vala_code_context_check
    at valacodecontext.c line 1248
  • #43 vala_compiler_run
    at valacompiler.c line 1495
  • #44 vala_compiler_main
    at valacompiler.c line 2674
  • #45 main
    at valacompiler.c line 2685

Comment 11 Matthias Berndt 2016-08-10 06:28:39 UTC
Hey Evan,

thanks, that's very helpful. Could you give me some instructions on how to reproduce the issue? Specifically, is there a way to tell sqlheavy's build system which valac to use?
Comment 12 Matthias Berndt 2016-08-10 06:32:12 UTC
Ah, never mind, make VALAC=$HOME/vala/compiler/valac VALAFLAGS="--vapidir $HOME/vala/vapi" did the trick :-)
Comment 13 Matthias Berndt 2016-08-10 10:40:14 UTC
OK, the problem seems to be caused by this line:

    private extern unowned GLib.HashTable g_hash_table_ref (GLib.HashTable ht);

The problem here is that the type parameters are simply not specified for the HashTable so the type parameters are just not given. IMO the compiler shouldn't accept code like that at all.

My suggestion would be to deprecate this syntax since adding the machinery to support this (probably some form of existential types) is IMO not worth the effort. The above declaration could easily be replaced by something like

    private extern unowned <K, V> GLib.HashTable<K, V> g_hash_table_ref (GLib.HashTable<K, V> ht);


In the meantime, I'll add some workaround for the crash.
Comment 14 Matthias Berndt 2016-08-10 22:08:47 UTC
Created attachment 333079 [details] [review]
bugfix + testcase

sqlheavy should now compile. I've added a test for the behaviour that sqlheavy relies on (that one doesn't have to specify generic type parameters) since that currently seems to be the only way to bind functions like g_hash_table_ref correctly. It's super ugly but for the time being I don't see any alternative.
Comment 15 Matthias Berndt 2016-08-11 10:07:38 UTC
Created attachment 333109 [details] [review]
bugfix + testcase

Simplified the code a bit
Comment 16 Al Thomas 2016-08-11 16:16:26 UTC
Review of attachment 333109 [details] [review]:

Patch applies and works for me. Rebuilt vala with the patch applied and no problems. All tests passed.
Comment 17 Jürg Billeter 2016-08-23 18:49:36 UTC
Review of attachment 333109 [details] [review]:

::: vala/valadatatype.vala
@@ +305,3 @@
 
+		if (data_type == null && target_type.data_type == null)
+			return true;

Do you know of a case where this is required or did you simply want to preserve the behavior when the two data_type members are both null?

I would rather drop this.
Comment 18 Matthias Berndt 2016-08-23 19:03:15 UTC
Hey Jürg,

Thanks for the review.

I don't know if such a case, so feel free to drop it.
Comment 19 Matthias Berndt 2016-08-23 19:04:17 UTC
*of* such a case, that is 
Comment 20 Jürg Billeter 2016-09-12 20:10:17 UTC
Created attachment 335401 [details] [review]
Updated patch

The patch breaks build of libgee and shotwell.

libgee/treemap.vala:1975.5-1975.20: error: Assignment: Cannot convert from `Gee.TreeMap.SubEntryIterator<K,V>' to `Gee.Iterator<Gee.TreeMap.Entry<K,V>>'

shotwell/src/core/ViewCollection.vala:649.30-649.37: error: Argument 1: Cannot convert from `Gee.Set<DataObject>' to `Gee.Collection<DataView>'
shotwell/src/MediaMonitor.vala:352.50-352.58: error: Argument 1: Cannot convert from `Gee.ArrayList<MediaSource>?' to `Gee.Collection<Monitorable>?'

These may actually be bugs in libgee and shotwell, respectively, however, I can't push this patch to vala master at this point with these pending issues.
Comment 21 Jürg Billeter 2016-09-12 20:15:17 UTC
It also breaks folks:

anti-linkable.vala:135.37-135.50: error: Argument 1: Cannot convert from `Folks.SmallSet<G>' to `Gee.Set<string>'
Comment 22 Rico Tzschichholz 2016-09-16 19:59:17 UTC
Those breakages might be unfortunate and actual coding-errors even, we can't ignore them since e.g. libgee is a core library and fixing this problem likely leads to an ABI break.
Comment 23 Matthias Berndt 2016-09-16 21:19:07 UTC
libgee is a core library, but aiui shotwell and folks are not. So does that imply that when libgee is fixed, this fix can be go to master if libgee is fixed?

Besides, this change will not result in an ABI break. It doesn't touch code generation at all and type errors can simply be resolved with a cast which aiui also doesn't affect code generation.

I would also like to propose that we actually _ask_ users what they would rather have: a compiler that tells them about the silly mistakes that they make _now and in the future_, or one that silently ignores all such errors in order to save them from correcting one that they made in the past. I don't think it's wise to simply decide that for them based on assumptions that nobody bothered to check.
Comment 24 Rico Tzschichholz 2016-09-16 21:41:49 UTC
I am refering to a possible ABI breaks of e.g. libgee while fixingsurfaced issues.
Comment 25 Matthias Berndt 2016-09-16 21:50:10 UTC
I don't understand. The bugs in libgee can be fixed by adding casts. How is this supposed to affect ABI compatibility? Surely casting some reference to another type is not going to affect the value of the underlying pointer?!
Comment 26 Jens Georg 2016-09-17 04:39:56 UTC
> These may actually be bugs in libgee and shotwell, respectively, however, I
> can't push this patch to vala master at this point with these pending issues.

I'll have a look at shotwell
Comment 27 Jens Georg 2016-09-17 06:33:51 UTC
 (valac:29658): GLib-GObject-WARNING **: invalid cast from 'ValaStruct' to 
'ValaInterface'   

I'm getting that warning with the patch and the code at wip/615830 (shotwell repository)
Comment 28 Jürg Billeter 2016-09-17 21:14:27 UTC
(In reply to Matthias Berndt from comment #23)
> I would also like to propose that we actually _ask_ users what they would
> rather have: a compiler that tells them about the silly mistakes that they
> make _now and in the future_, or one that silently ignores all such errors
> in order to save them from correcting one that they made in the past. I
> don't think it's wise to simply decide that for them based on assumptions
> that nobody bothered to check.

The missing check should definitely be merged. What I meant was that it would be very bad to merge it a few hours before hard code freeze, knowingly breaking the build of multiple projects. Also, we should verify that these are easily fixable bugs in application/library code and not issues in the compiler - at least for libgee and projects with a maintainer willing to help, such as shotwell.

We should merge this after 0.34.0 as soon as the above is fixed.
Comment 29 Matthias Berndt 2016-09-18 14:22:34 UTC
Ok, glad to hear this!
Comment 30 Matthias Berndt 2016-09-19 18:51:06 UTC
(In reply to Jens Georg from comment #27)
>  (valac:29658): GLib-GObject-WARNING **: invalid cast from 'ValaStruct' to 
> 'ValaInterface'   
> 
> I'm getting that warning with the patch and the code at wip/615830 (shotwell
> repository)
That's interesting. Can you provide more details? What revision have you compiled, what flags did you pass to configure, autogen.sh and make and which file caused that message to be printed?
Comment 31 Jens Georg 2016-09-19 19:03:54 UTC
commit de38563e742fcf4041779ea19ec9458f57fa3879 + the patch from this bug

which configure/autogen.sh do you mean? The problem with shotwell is that everything is compiled in one go so I can't tell you the file :(
Comment 32 Matthias Berndt 2016-09-19 19:14:03 UTC
Well, shotwell's autogen and configure of course. 

Anyhow, I think I managed to reproduce it in the mean time. I had to: 
- rip out everything to do with APPDATA_XML from the build system (apparently appdata-tools is dead and not shipped with Fedora any longer)
- export VALAC=$HOME/vala/compiler/valac
- add --vapidir $HOME/vala/vapi to COMMON_VALAFLAGS in common.am – apparently shotwell's build system doesn't believe in the VALAFLAGS env variable, oh well

Now debugging this might be a bit tricky because I have no idea what file the line number in the error message refers to…
Comment 33 Jürg Billeter 2016-09-19 19:19:12 UTC
I would suggest to run valac with G_DEBUG=fatal-warnings (or set a breakpoint), check the backtrace, and poke relevant variables with gdb, e.g., print vala_source_reference_get_file(...).
Comment 34 Jens Georg 2016-09-19 19:27:29 UTC
(In reply to Matthias Berndt from comment #32)
> Well, shotwell's autogen and configure of course. 
> 
> Anyhow, I think I managed to reproduce it in the mean time. I had to: 
> - rip out everything to do with APPDATA_XML from the build system
> (apparently appdata-tools is dead and not shipped with Fedora any longer)

That's called appstream-util now.

> - add --vapidir $HOME/vala/vapi to COMMON_VALAFLAGS in common.am –
> apparently shotwell's build system doesn't believe in the VALAFLAGS env
> variable, oh well

I would consider this a bug. I have to look into that.
Comment 35 Matthias Berndt 2016-09-19 19:32:09 UTC
Thanks Jürg! It seems to produce a core dump as I get the typical "Speicherabzug geschrieben" message, but I don't see a core file, do you have an idea where it might be? Getting a stack trace would be helpful indeed… I already set ulimit -c unlimited.

Sorry, I do Scala in my day job, so my skills with the typical C infrastructure are a bit rusty ;-)
Comment 36 Matthias Berndt 2016-09-19 19:37:49 UTC
Ah, nevermind, apparently systemd (coredumpctl) is in charge of core dumps these days…
Comment 37 Al Thomas 2016-09-19 19:44:10 UTC
If it's any help gdb can be run interactively for a backtrace:

gdb program
> run
> bt

For debug info on Fedora someone has put some details on the Vala install pages:
https://wiki.gnome.org/Projects/Vala/ValaOnLinux

Also the --debug switch in valac will annotate a C code line with the relevant Vala code line that produced it.
Comment 38 Matthias Berndt 2016-09-19 20:03:23 UTC
Hey Al,

thanks for replying. I've managed to obtain a somewhat meaningful stack trace from the core dump. The crash seems to be in SemanticAnalyzer.get_instance_base_type, specifically this bit of code

if (base_type.data_type is Class) {
  instance_base_type = new ObjectType ((Class) base_type.data_type);
} else {
  instance_base_type = new ObjectType ((Interface) base_type.data_type);
}

Now I don't know what led the original author to assume that base_type.data_type is always either a Class or an Interface, but apparently that doesn't hold any longer…
Comment 39 Matthias Berndt 2016-09-19 20:09:28 UTC
For anyone who's interested, a fairly minimal example that triggers the bug seems to be this:

struct Foo {
  public int x;
}
struct Bar : Foo {}
void main() {
  Foo f = Bar();
}

Now, that's enough for today, have a nice evening everybody :-)
Comment 40 Rico Tzschichholz 2016-09-19 20:17:26 UTC
So it is simply triggered by the usage of SemanticAnalyzer.get_instance_base_type_for_member() in the patch, and this method is not made for SimpleTypes/Structs.
Comment 41 Matthias Berndt 2016-09-20 22:49:41 UTC
So, I took a look at that code. Unfortunately it's a bit hard to tellif there are any types other than ObjectType and StructValueType that might be passed to get_instance_base_type_for_member. I guess we'll have to try and see. For now I've modified the code to handle Structs, I hope that'll be enough. If somebody would take a look that would be great.

I also noticed something else: There seems to be an annotation called simple_generics. Unfortunately it's not documented in the manual, but I've tried it and it seems that when calling a generic function or method annotated with it, no GType, GBoxedCopyFunc etc. are passed to it in the generated C code. Apparently the purpose is to bind functions like g_hash_table_ref, mentioned in Comment 13 and 14. That's great because then we might actually disallow code like in SQLheavy where GHashTable is used without parameters.

Alas, while it works at the function *call* site, it also generates a function *prototype* that still includes those parameters, which is unfortunate and makes me wonder if it's intended like that…
Comment 42 Matthias Berndt 2016-09-20 22:51:24 UTC
Created attachment 335952 [details] [review]
Updated patch
Comment 43 Matthias Berndt 2016-09-20 23:00:54 UTC
Created attachment 335954 [details] [review]
Updated patch

Added another test for the struct case
Comment 44 Matthias Berndt 2016-09-20 23:01:48 UTC
Created attachment 335955 [details] [review]
Updated patch

Added another test for the struct case
Comment 45 Al Thomas 2016-09-20 23:22:04 UTC
If it's any help the use of the simple_generics CCode attribute detail is covered here: 
https://wiki.gnome.org/Projects/Vala/LegacyBindings#Parameters_of_Variable_Type_.28Generics.29

Personally, I'm slightly uneasy that a function called get_instance_base_type_for_member is being used for structs, etc. To my mind keywords 'instance' and 'member' relate to OOP and object instantiation and the instance a function acts upon. This would explain why the original code does not cater for structs.

In general there need to be a set of utility functions in the semantic analyser for these types of query. You may have to create a new one or look for an alternative. Maybe https://bugzilla.gnome.org/show_bug.cgi?id=769501 might provide some inspiration. Thinking about this, it may even be need to be a utility function within the AST component. Other tools, such as an IDE in the future, may be using such utility functions so design now may be important later.
Comment 46 Matthias Berndt 2016-09-21 03:27:20 UTC
Hey Al,

thanks for the link. I'll look into it, but I think it's a separate issue for now.

Regarding your unease about the name, I don't see the problem to be honest. Classes and Structs in Vala have more in common than separates them. They have methods, constructors, member variables and type parameters and they form inheritance hierarchies. IOW, they behave for the most part like classes except for the limitations imposed by the runtime representation, i. e. no new fields in derived structs, no reference equality etc.. So I think it makes sense to deal with them in the same function, they're not fundamentally different from classes.

Regarding the needs of an IDE, I would very much prefer not to speculate about that. I don't see an obvious use case for such a function and would therefore default to YAGNI. It also seems to me that the primary requirement for an IDE would be a parser capable of dealing with broken input in a sensible way, and it seems pointless to worry about features beyond that for now. Let's focus on fixing what we have before taking on new use cases; there are, after all, a lot of bugs left to fix in valac.
Comment 47 Matthias Berndt 2016-09-21 04:01:19 UTC
Oh, I actually think that get_instance_base_type_for_member not working with structs is really just an oversight rather than any sort of design issue. It was possible to cause it to be called with a struct type before my patch, e. g.

struct Foo<T> {T t;}
struct Bar<T> : Foo<T> {}
void main() {
  int f = Bar<int>().t;
}

That crashes valac 0.32.1. It's now just called in cases it wasn't called before.
Comment 48 Maciej (Matthew) Piechotka 2016-09-21 04:20:33 UTC
Could you check also more complicated use-cases (skimming through initial patches it looked like it might not be handled). Like:

class Foo<K, V> {
    public abstract V foo(K k);
}

class Bar<V, K> : Foo<V, K> {
    override K foo(V v) {
        return null;
    }
}

class FooBar<K> : Bar<K, Foo<K, K>> {
    public K bar(K k) {
        return foo(k).foo(k);
    }
}
Comment 49 Al Thomas 2016-09-21 12:03:44 UTC
(In reply to Matthias Berndt from comment #46)
> Regarding the needs of an IDE...I don't see an obvious use case for such a
> function...It also seems to me that the primary requirement
> for an IDE would be a parser capable of dealing with broken input in a
> sensible way, and it seems pointless to worry about features beyond that for
> now.

The feature is autocompletion and function/method parameter information. So when using an object the IDE can find the inherited methods and show them for autocompletion and also show the arguments needed. Whether this function helps with that I don't know.

> Let's focus on fixing what we have before taking on new use cases;
> there are, after all, a lot of bugs left to fix in valac.

valac is a front end to libvala. A lot of tools, such as valadoc, anjuta, GNOME Builder, etc. use libvala for extracting information from Vala source files. So that use case already exists. e.g. https://bugzilla.gnome.org/show_bug.cgi?id=768817 At the moment I'm thinking another front end should exist, a libvala-ide-tools shared object, that provides such services in a stable API/ABI. I think this is something to consider when looking deeply at the libvala source code.
Comment 50 Matthias Berndt 2016-09-21 12:18:14 UTC
Hey Al,

you're right, the function may in fact be useful for that sort of purpose. However I frankly don't see how fixing it to work with structs makes it any less useful for those purposes than it already is. There may be ways to make it even more useful, e. g. by sticking it into a separate library, but I believe that's out of scope for this bug.
Comment 51 Matthias Berndt 2016-09-21 12:23:02 UTC
Hey Maciej,

could you go into a bit more detail on your example? Afaics it doesn't contain any type errors, how is it related to this bug?

The only thing that's interesting about this is that you flip the names of the type arguments, which might confuse the compiler. I actually fixed one source of compiler confusion with my patch to #768823 and there is a test case for that, maybe that is enough?
Comment 52 Al Thomas 2016-09-21 13:03:22 UTC
(In reply to Matthias Berndt from comment #50)
> you're right, the function may in fact be useful for that sort of purpose.
> However I frankly don't see how fixing it to work with structs makes it any
> less useful for those purposes than it already is.

Functionally there is no problem of course. It is naming things so code is self-documenting as much as possible. I'm probably getting confused between objects and basic types, but, yes, basic types in Vala are structs and have members. I don't think enums can inherit, but they also have members. If that needs testing as well, but enums are ints and so probably structs as well. I'm not sure about delegates.

> There may be ways to make it even more useful, e. g. by sticking it into
> a separate library, but I believe that's out of scope for this bug.

Sure, it is out of scope. Also I wasn't proposing to move the function out of libvala. The idea of libvala-ide-tools would be to use the existing libvala functions, but provide API/ABI stability, a friendlier high level API and probably some kind of session.
Comment 53 Matthias Berndt 2016-09-21 13:41:42 UTC
(In reply to Al Thomas from comment #52)
> Functionally there is no problem of course. It is naming things so code is
> self-documenting as much as possible.
So since your only gripe seems to be the name, could you suggest a better one?
Comment 54 Al Thomas 2016-09-25 15:42:15 UTC
(In reply to Matthias Berndt from comment #53)
> So since your only gripe seems to be the name
?? I was pointing out some strategic direction for future development, but those are long term goals. As far as the name goes, instead of changing the function from private to public, I suggest changing it to internal. Then when https://bugzilla.gnome.org/show_bug.cgi?id=771920 goes in it won't appear in libvala's dynamic symbol table and potentially get used by IDE writers.

I've looked through the Vala code base and wondered why the patch adds the check to DataType.compatible () and not Method.compatible () ,but no-one else has questioned that so I will look further another time.

As far as your patch goes: 

 - Why is instance_base_type = new ObjectType ((Interface) base_type.data_type); not necessary at all?
 - instance_base_type = null; is not needed if you are then going to assert or is that just to get past a compiler warning?
 - should the assert be assert_not_reached (); but really that is debugging code because as you said earlier "Unfortunately it's a bit hard to tellif there are any types other than ObjectType and StructValueType that might be passed to get_instance_base_type_for_member. I guess we'll have to try and see."
 - there should be a space between assert and the parentheses - https://wiki.gnome.org/Projects/Vala/Hacking#Coding_Style
Comment 55 Al Thomas 2016-09-25 15:43:14 UTC
BTW, your patch is in staging:

http://paldo.org:8010/builders/vala-staging/builds/97

That includes output from the failed builds if it is any help
Comment 56 Matthias Berndt 2016-09-25 17:00:40 UTC
Hey Al,

thanks, I didn't know about staging. That is helpful indeed! I couldn't get libgee's build system to work on my system (it complains about not finding geeutils, whatever that is), so it's useful to see the actual error messages. After checking the source code I believe they're legitimate.

Regarding your questions:
- there was no reason to treat Interfaces and Classes separately in the first place since either way an ObjectType is created (and not a ClassType or InterfaceType, which also exist but don't seem to be used here). So I could simplify that code by simply testing for and casting to ObjectType rather than treat Interfaces and Classes separately. Structs on the other hand are treated differently.
- right, I put that there to make it compile. With assert_not_reached that is not needed any longer :-). I'll upload a new version with that and the whitespace fix.
Comment 57 Matthias Berndt 2016-09-25 17:01:21 UTC
Created attachment 336215 [details] [review]
patch
Comment 58 Al Thomas 2016-09-25 17:35:22 UTC
Anyone got any thoughts on get_instance_base_type_for_member being 'internal' instead of 'public'?

Matthias, thanks for the quick response. If you do another iteration then g_assert_not_reached (); doesn't take an argument.
Comment 59 Matthias Berndt 2016-09-25 18:00:47 UTC
Created attachment 336226 [details] [review]
patch

made get_instance_base_type_for_member internal
Comment 60 Matthias Berndt 2016-09-25 18:04:52 UTC
Created attachment 336227 [details] [review]
patch

I'm a bit surprised because I thought I had compiled that code, yet it still had the argument to assert_not_reached… anyway, that's fixed now.
Comment 61 Matthias Berndt 2016-09-27 12:13:36 UTC
Hey Al,

I have also looked at method.compatible. It is broken indeed and needs to be fixed, but I wonder if it needs to be done in the context of this bug? Let's fix one problem at a time, I would really like to keep the scope small and fix one problem at a time.

We can discuss Method.compatible in bug 641418.
Comment 62 Jürg Billeter 2016-09-27 15:48:32 UTC
libgee master now builds with this patch.

Jens, can you please look into these issues in shotwell with vala master and the latest patch (currently in staging)?
http://paldo.org:8010/builders/vala-staging/builds/100/steps/shotwell/logs/stdio
Comment 63 Jens Georg 2016-09-27 17:09:29 UTC
Can you check the wip/615830 branch of shotwell? I didn't push it to master because of the warnings in comment 27

Otherwise I try to do it later but can't promise
Comment 64 Jens Georg 2016-09-27 20:07:09 UTC
Works on master now
Comment 65 Jürg Billeter 2016-09-28 07:20:35 UTC
Comment on attachment 336227 [details] [review]
patch

Pushed to master.
Comment 66 Jürg Billeter 2016-09-28 07:20:53 UTC
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.