[vala] Report error for recursive value types



commit da2d58c95f39fd142dc845f5df9cdcd55be32476
Author: Jürg Billeter <j bitron ch>
Date:   Sat Jun 6 18:22:15 2009 +0200

    Report error for recursive value types
    
    Fixes bug 584573.
---
 vala/valastruct.vala |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 8f5fbca..166edba 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -690,6 +690,22 @@ public class Vala.Struct : TypeSymbol {
 		return false;
 	}
 
+	bool is_recursive_value_type (DataType type) {
+		var struct_type = type as StructValueType;
+		if (struct_type != null) {
+			var st = (Struct) struct_type.type_symbol;
+			if (st == this) {
+				return true;
+			}
+			foreach (Field f in st.fields) {
+				if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.field_type)) {
+					return true;
+				}
+			}
+		}
+		return false;
+	}
+
 	public override bool check (SemanticAnalyzer analyzer) {
 		if (checked) {
 			return !error;
@@ -725,6 +741,12 @@ public class Vala.Struct : TypeSymbol {
 
 		foreach (Field f in fields) {
 			f.check (analyzer);
+
+			if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.field_type)) {
+				error = true;
+				Report.error (f.source_reference, "Recursive value types are not allowed");
+				return false;
+			}
 		}
 
 		foreach (Constant c in constants) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]