[vala/684-remove-field-context-from-symbolresolver] vala: added test case for nullable reference local variables
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/684-remove-field-context-from-symbolresolver] vala: added test case for nullable reference local variables
- Date: Tue, 16 Oct 2018 21:46:07 +0000 (UTC)
commit 3ad8371e683318b70960ef804a6e916d955729de
Author: Daniel Espinosa <esodan gmail com>
Date: Tue Oct 16 16:45:18 2018 -0500
vala: added test case for nullable reference local variables
tests/Makefile.am | 2 +-
tests/nullability/bug611223.vala | 5 ++++-
vala/valaparser.vala | 12 ++++++++++++
vala/valasymbolresolver.vala | 12 ------------
4 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 89020c012..b2a007a53 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -627,7 +627,7 @@ check-TESTS: $(TESTS) $(NON_NULL_TESTS)
if HAVE_LINUX
@EXEEXT=$(EXEEXT) EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)'
VALAFLAGS="--pkg linux" $(srcdir)/testrunner.sh $(LINUX_TESTS)
endif
- @EXEEXT=$(EXEEXT) EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)'
VALAFLAGS="--enable-experimental-non-null" $(srcdir)/testrunner.sh $(NON_NULL_TESTS)
+ @EXEEXT=$(EXEEXT) EXEEXT=$(EXEEXT) CFLAGS='$(CFLAGS)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)'
VALAFLAGS="--enable-experimental-non-null -D NON_NULL" $(srcdir)/testrunner.sh $(NON_NULL_TESTS)
EXTRA_DIST = \
testrunner.sh \
diff --git a/tests/nullability/bug611223.vala b/tests/nullability/bug611223.vala
index 3d054e58f..cb9d8de89 100644
--- a/tests/nullability/bug611223.vala
+++ b/tests/nullability/bug611223.vala
@@ -4,5 +4,8 @@ void main() {
string? some_null = nullable ?? null;
string also_non_null = null ?? non_null;
string really_non_null = non_null ?? nullable;
- string str = null; // Local Variables as Reference type, can be nullable
+#if NON_NULL
+#else
+ string str = null;
+#endif
}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index f110452b4..1a4fe8701 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -1811,6 +1811,18 @@ public class Vala.Parser : CodeVisitor {
type_copy = variable_type.copy ();
}
var local = parse_local_variable (type_copy);
+ if (!CodeContext.get ().experimental_non_null) {
+ // local reference variables are considered nullable
+ // except when using experimental non-null enhancements
+ if (local.variable_type is ReferenceType) {
+ var array_type = local.variable_type as ArrayType;
+ if (array_type != null && array_type.fixed_length) {
+ // local fixed length arrays are not nullable
+ } else {
+ local.variable_type.nullable = true;
+ }
+ }
+ }
block.add_statement (new DeclarationStatement (local, local.source_reference));
} while (accept (TokenType.COMMA));
expect (TokenType.SEMICOLON);
diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala
index ae57de834..a67a6dc09 100644
--- a/vala/valasymbolresolver.vala
+++ b/vala/valasymbolresolver.vala
@@ -379,18 +379,6 @@ public class Vala.SymbolResolver : CodeVisitor {
public override void visit_local_variable (LocalVariable local) {
local.accept_children (this);
- // if (!context.experimental_non_null) {
- // local reference variables are considered nullable
- // except when using experimental non-null enhancements
- // if (local.variable_type is ReferenceType) {
- // var array_type = local.variable_type as ArrayType;
- // if (array_type != null && array_type.fixed_length) {
- // local fixed length arrays are not nullable
- // } else {
- // local.variable_type.nullable = true;
- // }
- // }
- // }
}
public override void visit_initializer_list (InitializerList list) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]