Browse Source

Fixed NPE caused by Statement#getReturnType returning Null

kindlich 5 years ago
parent
commit
f85ee75d6f
No known key found for this signature in database

+ 2
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/BlockStatement.java View File

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.statement;
7 7
 
8 8
 import java.util.Arrays;
9 9
 import java.util.List;
10
+import java.util.Objects;
10 11
 import java.util.function.Consumer;
11 12
 import java.util.stream.Collectors;
12 13
 
@@ -96,6 +97,7 @@ public class BlockStatement extends Statement {
96 97
 	public StoredType getReturnType() {
97 98
 		final List<StoredType> collect = Arrays.stream(statements)
98 99
 				.map(Statement::getReturnType)
100
+				.filter(Objects::nonNull)
99 101
 				.distinct()
100 102
 				.collect(Collectors.toList());
101 103
 		if(collect.isEmpty())

+ 2
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/statement/ReturnStatement.java View File

@@ -11,6 +11,7 @@ import org.openzen.zencode.shared.ConcatMap;
11 11
 import org.openzen.zenscript.codemodel.expression.Expression;
12 12
 import org.openzen.zenscript.codemodel.expression.ExpressionTransformer;
13 13
 import org.openzen.zenscript.codemodel.scope.TypeScope;
14
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
14 15
 import org.openzen.zenscript.codemodel.type.StoredType;
15 16
 
16 17
 /**
@@ -28,7 +29,7 @@ public class ReturnStatement extends Statement {
28 29
 	
29 30
 	@Override
30 31
 	public StoredType getReturnType() {
31
-		return value.type;
32
+		return value != null ? value.type : BasicTypeID.VOID.stored();
32 33
 	}
33 34
 	
34 35
 	@Override

Loading…
Cancel
Save