parser/function-syntax-error.test \
parser/inner-array-size.test \
parser/invalid-brace.test \
+ parser/local-variable.vala \
parser/lock-statement.vala \
parser/main-block.vala \
parser/method-no-abstract-override.test \
--- /dev/null
+void main () {
+ {
+ var foo = "foo";
+ var bar = 42;
+ }
+ {
+ unowned var foo = "foo";
+ unowned var bar = 42;
+ }
+}
valausingdirective.vala \
valavaluetype.vala \
valavariable.vala \
+ valavartype.vala \
valaversion.vala \
valaversionattribute.vala \
valavoidtype.vala \
checked = true;
+ if (variable_type == null) {
+ variable_type = new VarType ();
+ }
+
if (!context.experimental_non_null) {
// local reference variables are considered nullable
// except when using experimental non-null enhancements
}
}
- if (variable_type != null) {
+ if (!(variable_type is VarType)) {
if (variable_type is VoidType) {
error = true;
Report.error (source_reference, "'void' not supported as variable type");
}
}
- if (variable_type == null) {
+ if (variable_type is VarType) {
/* var type */
if (initializer == null) {
return false;
}
+ bool value_owned = variable_type.value_owned;
variable_type = initializer.value_type.copy ();
- variable_type.value_owned = true;
+ variable_type.value_owned = value_owned;
variable_type.floating_reference = false;
initializer.target_type = variable_type;
void parse_local_variable_declarations (Block block) throws ParseError {
var begin = get_location ();
DataType variable_type;
- if (accept (TokenType.VAR)) {
- variable_type = null;
+ if (accept (TokenType.UNOWNED) && accept (TokenType.VAR)) {
+ variable_type = new VarType (false);
} else {
- variable_type = parse_type (true, true);
+ rollback (begin);
+ if (accept (TokenType.VAR)) {
+ variable_type = new VarType ();
+ } else {
+ variable_type = parse_type (true, true);
+ }
}
bool is_first = true;
do {
- if (variable_type == null && accept (TokenType.OPEN_PARENS)) {
+ if (variable_type is VarType && variable_type.value_owned && accept (TokenType.OPEN_PARENS)) {
// tuple
begin = get_location ();
--- /dev/null
+/* valavartype.vala
+ *
+ * Copyright (C) 2019 Rico Tzschichholz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Rico Tzschichholz <ricotz@ubuntu.com>
+ */
+
+/**
+ * A to be inferred data type.
+ */
+public class Vala.VarType : DataType {
+ public VarType (bool value_owned = true) {
+ this.value_owned = value_owned;
+ }
+
+ public override string to_qualified_string (Scope? scope) {
+ return (value_owned ? "var" : "unowned var");
+ }
+
+ public override DataType copy () {
+ return new VarType (value_owned);
+ }
+}