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 562063 - Cannot use typeof inside foreach
Cannot use typeof inside foreach
Status: RESOLVED NOTABUG
Product: vala
Classification: Core
Component: Semantic Analyzer
0.5.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 573075 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-11-23 22:33 UTC by ccadete
Modified: 2010-05-27 21:16 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description ccadete 2008-11-23 22:33:35 UTC
Please describe the problem:
Cannot use typeof inside foreach

Steps to reproduce:
using GLib;


public class Test {
        public static void main(string[] args){
                var array = new string[10] { "0", "1", "2"};
                foreach( string item in array ){
                        stdout.printf(typeof(item));
                }
       

Actual results:
Main.vala:10.46-10.49: error: The type name `item' could not be found
                        stdout.printf(typeof(item));
                                             ^^^^


Expected results:


Does this happen every time?


Other information:
Comment 1 Jürg Billeter 2008-11-24 18:10:15 UTC
typeof returns the GLib.Type of a static type, for example typeof(string) returns the GLib.Type for strings. However, it cannot be used to return the static type of a variable, and that's itentional.

You can retrieve the dynamic type of an object by using the get_type() method, this will only work for GObject derived types, though.
Comment 2 Jürg Billeter 2010-05-27 21:16:28 UTC
*** Bug 573075 has been marked as a duplicate of this bug. ***