check type of variable initializer
authorJuerg Billeter <j@bitron.ch>
Tue, 22 Jan 2008 17:05:24 +0000 (17:05 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 22 Jan 2008 17:05:24 +0000 (17:05 +0000)
2008-01-22  Juerg Billeter  <j@bitron.ch>

* vala/valasemanticanalyzer.vala: check type of variable initializer

* gee/hashmap.vala, gee/hashset.vala, vala/valasymbol.vala: fix invalid
  variable initializers

svn path=/trunk/; revision=884

ChangeLog
gee/hashmap.vala
gee/hashset.vala
vala/valasemanticanalyzer.vala
vala/valasymbol.vala

index db978ab..c2dec4b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-01-22  Jürg Billeter  <j@bitron.ch>
 
+       * vala/valasemanticanalyzer.vala: check type of variable initializer
+
+       * gee/hashmap.vala, gee/hashset.vala, vala/valasymbol.vala: fix invalid
+         variable initializers
+
+2008-01-22  Jürg Billeter  <j@bitron.ch>
+
        * vapi/packages/gdk-pixbuf-2.0/, vapi/packages/gdk-2.0/,
          vapi/gdk-pixbuf-2.0.vapi, vapi/gdk-2.0.vapi: add bindings for
          gdk-pixbuf-2.0, fixes bug 501589
index c6cd0f9..3868769 100644 (file)
@@ -141,7 +141,7 @@ public class Gee.HashMap<K,V> : Object, Map<K,V> {
        private void resize () {
                if ((_array_size >= 3 * _nnodes && _array_size >= MIN_SIZE) ||
                    (3 * _array_size <= _nnodes && _array_size < MAX_SIZE)) {
-                       int new_array_size = SpacedPrimes.closest (_nnodes);
+                       int new_array_size = (int) SpacedPrimes.closest (_nnodes);
                        new_array_size = new_array_size.clamp (MIN_SIZE, MAX_SIZE);
 
                        Node<K,V>[] new_nodes = new Node<K,V>[new_array_size];
index afa674d..36ec346 100644 (file)
@@ -126,7 +126,7 @@ public class Gee.HashSet<G> : Object, Iterable<G>, Collection<G>, Set<G> {
        private void resize () {
                if ((_array_size >= 3 * _nnodes && _array_size >= MIN_SIZE) ||
                    (3 * _array_size <= _nnodes && _array_size < MAX_SIZE)) {
-                       int new_array_size = SpacedPrimes.closest (_nnodes);
+                       int new_array_size = (int) SpacedPrimes.closest (_nnodes);
                        new_array_size = new_array_size.clamp (MIN_SIZE, MAX_SIZE);
 
                        Node<G>[] new_nodes = new Node<G>[new_array_size];
index f4a370b..9bc27cb 100644 (file)
@@ -738,6 +738,12 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                                }
                        }
 
+                       if (!decl.initializer.static_type.compatible (decl.type_reference)) {
+                               decl.error = true;
+                               Report.error (decl.source_reference, "Assignment: Cannot convert from `%s' to `%s'".printf (decl.initializer.static_type.to_string (), decl.type_reference.to_string ()));
+                               return;
+                       }
+
                        if (decl.initializer.static_type.transfers_ownership) {
                                /* rhs transfers ownership of the expression */
                                if (!(decl.type_reference is PointerType) && !decl.type_reference.takes_ownership) {
index 21118c1..3883ceb 100644 (file)
@@ -1,6 +1,6 @@
 /* valasymbol.vala
  *
- * Copyright (C) 2006-2007  Jürg Billeter
+ * Copyright (C) 2006-2008  Jürg Billeter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -202,7 +202,7 @@ public abstract class Vala.Symbol : CodeNode {
                                if (!prev_upper || (i.len () >= 2 && !next_upper)) {
                                        /* previous character wasn't upper case or
                                         * next character isn't upper case*/
-                                       int len = result.str.len ();
+                                       long len = result.str.len ();
                                        if (len != 1 && result.str.offset (len - 2).get_char () != '_') {
                                                /* we're not creating 1 character words */
                                                result.append_c ('_');