GNOME Bugzilla – Bug 635983
Nested types in generic types
Last modified: 2017-12-06 11:43:00 UTC
Nested type inside generic type causes valac to crash. Most plausible example would be: class customIterable<T> : Iterable<T> { ... class customIterator : Iterator<T> { ... } ... } While trying to narrow down to the part that causes an error even succeeded in crashing compiler compleatly with "Segmentation vialation". All versions of compiler are subjeted to an error ( tested on 0.10.1 & vala-git ). Examples attached
Created attachment 175409 [details] assert in vala_semantic_analyzer_get_actual_type
Created attachment 175410 [details] Segmentation violation while trying to compile
The above example is invalid code. Inner classes of generic classes do not inherit the generic type parameters. The crash is still a bug, of course.
Created attachment 243280 [details] [review] Report error instead of assertion Report error for assert (Bug 635983 - Nested types in generic types)
Review of attachment 243280 [details] [review]: Thanks for the patch, however this is equivalent to an assertion, because it doesn't give any hint to the programmer on how to solve the problem. I'd rather understand the context of this bug in the code, i.e. inner class using parent class generic type, and report an appropriate error.
At least the error message is more verbose than the assertion, it shows the symbol name and source location. Would the following error be more correct? "Unable to determine generic type for symbol %s"
I'd like "Inheriting generic type from parent class %s is not supported" or such, that is give an actual hint to the user, otherwise that's a too generic error.
Created attachment 243841 [details] [review] Report error for assert (Bug 635983 - Nested types in generic types) Comment 7: IMHO your understanding of the error is not correct, the code in the bug report is invalid. It can be made working by defining the inner class as : public class Point<T> : Object {} public class Box<T> : Object { public class Point<T> : Object { ... } public Box( T x, T y, T width, T height ) { Position = new Point<T>( x, y ); ... } ... } Attaching a new patch that reports following: /usr/local/bin/valac --pkg glib-2.0 bug635983.vala --pkg gtk+-3.0 bug635983.vala:10.22-10.25: error: Type Box.Point does not inherit the generic type from Box public T X { get; private set; }
Yes, but(In reply to comment #8) > Created an attachment (id=243841) [details] [review] > Report error for assert (Bug 635983 - Nested types in generic types) > > Comment 7: IMHO your understanding of the error is not correct, the code in the > bug report is invalid. > It can be made working by defining the inner class as : public class Point<T> : > Object {} But that's another thing, the bug report is about: public class Foo<T> { public class Bar { ... use T } } What am I not understanding?
Review of attachment 243841 [details] [review]: This is exactly the same patch as before, except with a different message. As I said, the code must understand the particular context of the bug, because "instance == null" is too generic and might happen in a different case.
*** This bug has been marked as a duplicate of bug 587905 ***