|
@@ -5,31 +5,21 @@
|
5
|
5
|
*/
|
6
|
6
|
package org.openzen.zenscript.validator.visitors;
|
7
|
7
|
|
8
|
|
-import java.util.HashSet;
|
9
|
|
-import java.util.Set;
|
10
|
|
-import java.util.regex.Pattern;
|
11
|
|
-import org.openzen.zencode.shared.CodePosition;
|
12
|
|
-import org.openzen.zenscript.codemodel.AccessScope;
|
13
|
|
-import org.openzen.zenscript.codemodel.FunctionHeader;
|
14
|
|
-import org.openzen.zenscript.codemodel.FunctionParameter;
|
15
|
|
-import org.openzen.zenscript.codemodel.HighLevelDefinition;
|
16
|
|
-import org.openzen.zenscript.codemodel.Modifiers;
|
17
|
|
-import org.openzen.zenscript.codemodel.generic.TypeParameterBound;
|
18
|
|
-import org.openzen.zenscript.codemodel.generic.GenericParameterBoundVisitor;
|
19
|
|
-import org.openzen.zenscript.codemodel.generic.ParameterSuperBound;
|
20
|
|
-import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
|
21
|
|
-import org.openzen.zenscript.codemodel.generic.TypeParameter;
|
22
|
|
-import org.openzen.zenscript.codemodel.member.EnumConstantMember;
|
23
|
|
-import org.openzen.zenscript.codemodel.member.FieldMember;
|
24
|
|
-import org.openzen.zenscript.codemodel.scope.TypeScope;
|
25
|
|
-import org.openzen.zenscript.codemodel.statement.VarStatement;
|
26
|
|
-import org.openzen.zenscript.codemodel.type.ArrayTypeID;
|
27
|
|
-import org.openzen.zenscript.validator.ValidationLogEntry;
|
28
|
|
-import static org.openzen.zenscript.validator.ValidationLogEntry.Code.*;
|
29
|
|
-import org.openzen.zenscript.validator.Validator;
|
|
8
|
+import org.openzen.zencode.shared.*;
|
|
9
|
+import org.openzen.zenscript.codemodel.*;
|
|
10
|
+import org.openzen.zenscript.codemodel.expression.*;
|
|
11
|
+import org.openzen.zenscript.codemodel.generic.*;
|
|
12
|
+import org.openzen.zenscript.codemodel.member.*;
|
|
13
|
+import org.openzen.zenscript.codemodel.scope.*;
|
|
14
|
+import org.openzen.zenscript.codemodel.statement.*;
|
|
15
|
+import org.openzen.zenscript.codemodel.type.*;
|
|
16
|
+import org.openzen.zenscript.validator.*;
|
30
|
17
|
import org.openzen.zenscript.validator.analysis.ExpressionScope;
|
31
|
|
-import org.openzen.zenscript.codemodel.type.TypeID;
|
32
|
|
-import org.openzen.zenscript.validator.TypeContext;
|
|
18
|
+
|
|
19
|
+import java.util.*;
|
|
20
|
+import java.util.regex.*;
|
|
21
|
+
|
|
22
|
+import static org.openzen.zenscript.validator.ValidationLogEntry.Code.*;
|
33
|
23
|
|
34
|
24
|
/**
|
35
|
25
|
*
|
|
@@ -64,13 +54,15 @@ public class ValidationUtils {
|
64
|
54
|
|
65
|
55
|
parameterNames.add(parameter.name);
|
66
|
56
|
typeValidator.validate(TypeContext.PARAMETER_TYPE, parameter.type);
|
67
|
|
-
|
68
|
|
- if (parameter.defaultValue != null) {
|
69
|
|
- parameter.defaultValue.accept(new ExpressionValidator(target, new DefaultParameterValueExpressionScope(access)));
|
70
|
|
- if (!parameter.defaultValue.type.equals(parameter.type)) {
|
71
|
|
- target.logError(INVALID_TYPE, position, "default value does not match parameter type");
|
72
|
|
- }
|
73
|
|
- }
|
|
57
|
+
|
|
58
|
+ final Expression defaultValue = parameter.defaultValue;
|
|
59
|
+ if (defaultValue != null) {
|
|
60
|
+ defaultValue.accept(new ExpressionValidator(target, new DefaultParameterValueExpressionScope(access)));
|
|
61
|
+ if(!defaultValue.type.equals(parameter.type) && !defaultValue.type
|
|
62
|
+ .canCastImplicit(parameter.type)) {
|
|
63
|
+ target.logError(INVALID_TYPE, position, "default value does not match parameter type");
|
|
64
|
+ }
|
|
65
|
+ }
|
74
|
66
|
|
75
|
67
|
if (parameter.variadic) {
|
76
|
68
|
if (i != header.parameters.length - 1) {
|