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 635983 - Nested types in generic types
Nested types in generic types
Status: RESOLVED DUPLICATE of bug 587905
Product: vala
Classification: Core
Component: Generics
0.11.x
Other All
: Urgent critical
: ---
Assigned To: Vala maintainers
Vala maintainers
crash-on-invalid-code
Depends on:
Blocks:
 
 
Reported: 2010-11-28 13:44 UTC by Pavel Aslanov
Modified: 2017-12-06 11:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
assert in vala_semantic_analyzer_get_actual_type (546 bytes, text/x-vala)
2010-11-28 13:45 UTC, Pavel Aslanov
  Details
Segmentation violation while trying to compile (591 bytes, text/x-vala)
2010-11-28 13:46 UTC, Pavel Aslanov
  Details
Report error instead of assertion (1.18 KB, patch)
2013-05-04 09:21 UTC, geert jordaens
needs-work Details | Review
Report error for assert (Bug 635983 - Nested types in generic types) (1.23 KB, patch)
2013-05-11 10:24 UTC, geert jordaens
needs-work Details | Review

Description Pavel Aslanov 2010-11-28 13:44:04 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
Comment 1 Pavel Aslanov 2010-11-28 13:45:20 UTC
Created attachment 175409 [details]
assert in vala_semantic_analyzer_get_actual_type
Comment 2 Pavel Aslanov 2010-11-28 13:46:52 UTC
Created attachment 175410 [details]
Segmentation violation while trying to compile
Comment 3 Jürg Billeter 2010-12-19 14:22:22 UTC
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.
Comment 4 geert jordaens 2013-05-04 09:21:51 UTC
Created attachment 243280 [details] [review]
Report error instead of assertion

Report error for assert (Bug 635983 - Nested types in generic types)
Comment 5 Luca Bruno 2013-05-04 11:11:30 UTC
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.
Comment 6 geert jordaens 2013-05-10 21:18:28 UTC
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"
Comment 7 Luca Bruno 2013-05-11 07:13:25 UTC
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.
Comment 8 geert jordaens 2013-05-11 10:24:50 UTC
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; }
Comment 9 Luca Bruno 2013-05-11 11:19:03 UTC
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?
Comment 10 Luca Bruno 2013-05-11 11:21:49 UTC
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.
Comment 11 Florian Brosch 2013-05-11 14:10:10 UTC

*** This bug has been marked as a duplicate of bug 587905 ***