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 530422 - invalid code from const strings as default value of properties
invalid code from const strings as default value of properties
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.3.x
Other All
: Normal minor
: ---
Assigned To: Jürg Billeter
Vala maintainers
: 538776 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-04-28 18:53 UTC by Evan Nemerson
Modified: 2008-10-17 12:15 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Evan Nemerson 2008-04-28 18:53:04 UTC
When trying to use a const string as the default value for a property, it generates invalid C (referencing _tmpN variables which were not declared).


nemequ@desktop:~/t$ cat test.vala
public const string BAR = "Doesn't!\n";
public const string BAZ = "Works!\n";

public class Foo : GLib.Object {
  public string a { get; set; default = "Works!\n"; }
  public string b = "Works!\n";
  public string c { get; set; default = BAR; }
  public string d = BAR;
  public string e;

  construct {
    this.e = BAZ;
  }
}

static int main(string[] args) {
  var foo = new Foo();
  GLib.stderr.printf(foo.a);
  GLib.stderr.printf(foo.b);
  GLib.stderr.printf(foo.c);
  GLib.stderr.printf(foo.d);
  GLib.stderr.printf(foo.e);
  return 0;
}
nemequ@desktop:~/t$ valac -o test --pkg glib-2.0 test.vala
test.c: In function ‘foo_constructor’:
test.c:80: error: conflicting types for ‘_tmp3’
test.c:78: error: previous declaration of ‘_tmp3’ was here
test.c:84: warning: assignment discards qualifiers from pointer target type
test.c: In function ‘foo_init’:
test.c:140: error: ‘_tmp0’ undeclared (first use in this function)
test.c:140: error: (Each undeclared identifier is reported only once
test.c:140: error: for each function it appears in.)
test.c:141: error: ‘_tmp1’ undeclared (first use in this function)
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
Comment 1 Jürg Billeter 2008-05-02 20:49:23 UTC
Confirming.
Comment 2 Jürg Billeter 2008-10-09 20:45:40 UTC
*** Bug 538776 has been marked as a duplicate of this bug. ***
Comment 3 Jürg Billeter 2008-10-17 12:15:45 UTC
2008-10-17  Jürg Billeter  <j@bitron.ch>

	* vala/valabinaryexpression.vala:
	* vala/valaexpression.vala:
	* vala/valamemberaccess.vala:
	* vala/valastringliteral.vala:
	* gobject/valaccodegenerator.vala:

	Extend non-null check when managing memory, fixes bug 530422

Fixed in r1849.