From 03cab8916033dc06fb35e7835a83a95ea4a2ba9b Mon Sep 17 00:00:00 2001 From: Juerg Billeter Date: Thu, 8 May 2008 19:01:40 +0000 Subject: [PATCH] Check number of type arguments in object creation expression, patch by 2008-05-08 Juerg Billeter * vala/valasemanticanalyzer.vala: * vala/valastruct.vala: Check number of type arguments in object creation expression, patch by Andreas Brauchli, fixes bug 528833 svn path=/trunk/; revision=1341 --- ChangeLog | 8 ++++++++ vala/valasemanticanalyzer.vala | 17 +++++++++++++++++ vala/valastruct.vala | 9 +++++++++ 3 files changed, 34 insertions(+) diff --git a/ChangeLog b/ChangeLog index cfee637..cdccbaa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-05-08 Jürg Billeter + + * vala/valasemanticanalyzer.vala: + * vala/valastruct.vala: + + Check number of type arguments in object creation expression, + patch by Andreas Brauchli, fixes bug 528833 + 2008-05-08 Jaap A. Haitsma reviewed by: Jürg Billeter diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 91f1cf5..e594fda 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -2313,9 +2313,14 @@ public class Vala.SemanticAnalyzer : CodeVisitor { expr.static_type = expr.type_reference.copy (); expr.static_type.transfers_ownership = true; + int given_num_type_args = expr.type_reference.get_type_arguments ().size; + int expected_num_type_args = 0; + if (type is Class) { var cl = (Class) type; + expected_num_type_args = cl.get_type_parameters ().size; + if (expr.struct_creation) { expr.error = true; Report.error (expr.source_reference, "syntax error, use `new' to create new objects"); @@ -2344,6 +2349,8 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } else if (type is Struct) { var st = (Struct) type; + expected_num_type_args = st.get_type_parameters ().size; + if (!expr.struct_creation) { Report.warning (expr.source_reference, "deprecated syntax, don't use `new' to initialize structs"); } @@ -2355,6 +2362,16 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } } + if (expected_num_type_args > given_num_type_args) { + expr.error = true; + Report.error (expr.source_reference, "too few type arguments"); + return; + } else if (expected_num_type_args < given_num_type_args) { + expr.error = true; + Report.error (expr.source_reference, "too many type arguments"); + return; + } + if (expr.symbol_reference == null && expr.get_argument_list ().size != 0) { expr.static_type = null; expr.error = true; diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 8b13fb9..bd97bd0 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -80,6 +80,15 @@ public class Vala.Struct : Typesymbol { } /** + * Returns a copy of the type parameter list. + * + * @return list of type parameters + */ + public Collection get_type_parameters () { + return new ReadOnlyCollection (type_parameters); + } + + /** * Adds the specified constant as a member to this struct. * * @param c a constant -- 2.7.4