Преглед на файлове

fix optionals not inheriting nullable and expecting a default type

Jared преди 5 години
родител
ревизия
93d75695ec
No account linked to committer's email address

+ 18
- 76
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java Целия файл

@@ -5,80 +5,22 @@
5 5
  */
6 6
 package org.openzen.zencode.java;
7 7
 
8
-import java.lang.reflect.AnnotatedType;
9
-import java.lang.reflect.Field;
10
-import java.lang.reflect.Method;
11
-import java.lang.reflect.Member;
12
-import java.lang.reflect.Modifier;
13
-import java.lang.reflect.Parameter;
14
-import java.lang.reflect.ParameterizedType;
15
-import java.lang.reflect.Type;
16
-import java.lang.reflect.TypeVariable;
17
-import java.util.Collections;
18
-import java.util.HashMap;
19
-import java.util.Map;
20
-import org.openzen.zencode.shared.CodePosition;
21
-import org.openzen.zenscript.codemodel.FunctionHeader;
22
-import org.openzen.zenscript.codemodel.FunctionParameter;
23
-import org.openzen.zenscript.codemodel.GenericMapper;
24
-import org.openzen.zenscript.codemodel.HighLevelDefinition;
25
-import org.openzen.zenscript.codemodel.Modifiers;
26
-import org.openzen.zenscript.codemodel.Module;
27
-import org.openzen.zenscript.codemodel.ModuleSpace;
28
-import org.openzen.zenscript.codemodel.OperatorType;
29
-import org.openzen.zenscript.codemodel.PackageDefinitions;
30
-import org.openzen.zenscript.codemodel.SemanticModule;
31
-import org.openzen.zenscript.codemodel.definition.ClassDefinition;
32
-import org.openzen.zenscript.codemodel.definition.EnumDefinition;
33
-import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
34
-import org.openzen.zenscript.codemodel.definition.StructDefinition;
35
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
36
-import org.openzen.zenscript.codemodel.expression.ConstantByteExpression;
37
-import org.openzen.zenscript.codemodel.expression.ConstantDoubleExpression;
38
-import org.openzen.zenscript.codemodel.expression.ConstantFloatExpression;
39
-import org.openzen.zenscript.codemodel.expression.ConstantIntExpression;
40
-import org.openzen.zenscript.codemodel.expression.ConstantLongExpression;
41
-import org.openzen.zenscript.codemodel.expression.ConstantSByteExpression;
42
-import org.openzen.zenscript.codemodel.expression.ConstantShortExpression;
43
-import org.openzen.zenscript.codemodel.expression.ConstantStringExpression;
44
-import org.openzen.zenscript.codemodel.expression.ConstantUIntExpression;
45
-import org.openzen.zenscript.codemodel.expression.ConstantULongExpression;
46
-import org.openzen.zenscript.codemodel.expression.ConstantUShortExpression;
47
-import org.openzen.zenscript.codemodel.expression.Expression;
48
-import org.openzen.zenscript.codemodel.expression.ExpressionSymbol;
49
-import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;
50
-import org.openzen.zenscript.codemodel.expression.StorageCastExpression;
51
-import org.openzen.zenscript.codemodel.generic.ParameterTypeBound;
52
-import org.openzen.zenscript.codemodel.generic.TypeParameter;
53
-import org.openzen.zenscript.codemodel.member.CasterMember;
54
-import org.openzen.zenscript.codemodel.member.ConstructorMember;
55
-import org.openzen.zenscript.codemodel.member.FieldMember;
56
-import org.openzen.zenscript.codemodel.member.GetterMember;
57
-import org.openzen.zenscript.codemodel.member.ImplementationMember;
58
-import org.openzen.zenscript.codemodel.member.MethodMember;
59
-import org.openzen.zenscript.codemodel.member.OperatorMember;
60
-import org.openzen.zenscript.codemodel.member.SetterMember;
61
-import org.openzen.zenscript.codemodel.member.ref.FunctionalMemberRef;
62
-import org.openzen.zenscript.codemodel.partial.PartialStaticMemberGroupExpression;
63
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
64
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
65
-import org.openzen.zenscript.codemodel.type.ISymbol;
66
-import org.openzen.zenscript.codemodel.type.StoredType;
67
-import org.openzen.zenscript.codemodel.type.StringTypeID;
68
-import org.openzen.zenscript.codemodel.type.TypeID;
69
-import org.openzen.zenscript.codemodel.type.member.BuiltinID;
70
-import org.openzen.zenscript.codemodel.type.member.TypeMembers;
71
-import org.openzen.zenscript.codemodel.type.storage.AutoStorageTag;
72
-import org.openzen.zenscript.codemodel.type.storage.StaticStorageTag;
73
-import org.openzen.zenscript.codemodel.type.storage.StorageTag;
74
-import org.openzen.zenscript.javashared.JavaClass;
75
-import org.openzen.zenscript.javashared.JavaCompiledModule;
76
-import org.openzen.zenscript.javashared.JavaField;
77
-import org.openzen.zenscript.javashared.JavaFunctionalInterfaceStorageTag;
78
-import org.openzen.zenscript.javashared.JavaImplementation;
79
-import org.openzen.zenscript.javashared.JavaMethod;
80
-import org.openzen.zenscript.javashared.JavaModifiers;
81
-import stdlib.Strings;
8
+import org.openzen.zencode.shared.*;
9
+import org.openzen.zenscript.codemodel.*;
10
+import org.openzen.zenscript.codemodel.definition.*;
11
+import org.openzen.zenscript.codemodel.expression.*;
12
+import org.openzen.zenscript.codemodel.generic.*;
13
+import org.openzen.zenscript.codemodel.member.*;
14
+import org.openzen.zenscript.codemodel.member.ref.*;
15
+import org.openzen.zenscript.codemodel.partial.*;
16
+import org.openzen.zenscript.codemodel.type.*;
17
+import org.openzen.zenscript.codemodel.type.member.*;
18
+import org.openzen.zenscript.codemodel.type.storage.*;
19
+import org.openzen.zenscript.javashared.*;
20
+import stdlib.*;
21
+
22
+import java.lang.reflect.*;
23
+import java.util.*;
82 24
 
83 25
 /**
84 26
  * @author Stan Hebben
@@ -542,7 +484,7 @@ public class JavaNativeModule {
542 484
 		if (parameter.isAnnotationPresent(ZenCodeType.Optional.class)) {
543 485
 			Expression defaultValue = type.type.getDefaultValue();
544 486
 			if (defaultValue == null)
545
-				throw new IllegalArgumentException(type.toString() + " doesn't have a default value");
487
+			    defaultValue = new NullExpression(CodePosition.NATIVE);
546 488
 			return defaultValue;
547 489
 		} else if (parameter.isAnnotationPresent(ZenCodeType.OptionalInt.class)) {
548 490
 			ZenCodeType.OptionalInt annotation = parameter.getAnnotation(ZenCodeType.OptionalInt.class);
@@ -640,7 +582,7 @@ public class JavaNativeModule {
640 582
 		else if (annotatedType.isAnnotationPresent(ZenCodeType.NullableUSize.class))
641 583
 			return registry.getOptional(BasicTypeID.USIZE).stored();
642 584
 		
643
-		boolean nullable = annotatedType.isAnnotationPresent(ZenCodeType.Nullable.class);
585
+		boolean nullable = annotatedType.isAnnotationPresent(ZenCodeType.Nullable.class) || annotatedType.isAnnotationPresent(ZenCodeType.Optional.class);
644 586
 		boolean unsigned = annotatedType.isAnnotationPresent(ZenCodeType.Unsigned.class);
645 587
 		
646 588
 		Type type = annotatedType.getType();

+ 12
- 24
Validator/src/main/java/org/openzen/zenscript/validator/visitors/ExpressionValidator.java Целия файл

@@ -5,30 +5,18 @@
5 5
  */
6 6
 package org.openzen.zenscript.validator.visitors;
7 7
 
8
-import java.util.HashSet;
9
-import java.util.Set;
10
-import org.openzen.zencode.shared.CodePosition;
11
-import org.openzen.zenscript.codemodel.FunctionHeader;
12
-import org.openzen.zenscript.codemodel.FunctionParameter;
13
-import org.openzen.zenscript.codemodel.Modifiers;
14
-import org.openzen.zenscript.codemodel.definition.EnumDefinition;
15
-import org.openzen.zenscript.codemodel.definition.VariantDefinition;
8
+import org.openzen.zencode.shared.*;
9
+import org.openzen.zenscript.codemodel.*;
10
+import org.openzen.zenscript.codemodel.definition.*;
16 11
 import org.openzen.zenscript.codemodel.expression.*;
17
-import org.openzen.zenscript.codemodel.expression.switchvalue.EnumConstantSwitchValue;
18
-import org.openzen.zenscript.codemodel.expression.switchvalue.VariantOptionSwitchValue;
19
-import org.openzen.zenscript.codemodel.member.EnumConstantMember;
20
-import org.openzen.zenscript.codemodel.member.ref.DefinitionMemberRef;
21
-import org.openzen.zenscript.codemodel.member.ref.FieldMemberRef;
22
-import org.openzen.zenscript.codemodel.type.ArrayTypeID;
23
-import org.openzen.zenscript.codemodel.type.AssocTypeID;
24
-import org.openzen.zenscript.codemodel.type.BasicTypeID;
25
-import org.openzen.zenscript.codemodel.type.RangeTypeID;
26
-import org.openzen.zenscript.codemodel.type.StoredType;
27
-import org.openzen.zenscript.codemodel.type.StringTypeID;
28
-import org.openzen.zenscript.validator.TypeContext;
29
-import org.openzen.zenscript.validator.ValidationLogEntry;
30
-import org.openzen.zenscript.validator.Validator;
31
-import org.openzen.zenscript.validator.analysis.ExpressionScope;
12
+import org.openzen.zenscript.codemodel.expression.switchvalue.*;
13
+import org.openzen.zenscript.codemodel.member.*;
14
+import org.openzen.zenscript.codemodel.member.ref.*;
15
+import org.openzen.zenscript.codemodel.type.*;
16
+import org.openzen.zenscript.validator.*;
17
+import org.openzen.zenscript.validator.analysis.*;
18
+
19
+import java.util.*;
32 20
 
33 21
 /**
34 22
  *
@@ -776,7 +764,7 @@ public class ExpressionValidator implements ExpressionVisitor<Void> {
776 764
 			}
777 765
 			
778 766
 			FunctionParameter parameter = instancedHeader.getParameter(isVariadic, i);
779
-			if (!parameter.type.equals(argument.type)) {
767
+			if (!parameter.type.equals(argument.type) && !parameter.defaultValue.type.equals(argument.type)) {
780 768
 				validator.logError(
781 769
 						ValidationLogEntry.Code.INVALID_CALL_ARGUMENT,
782 770
 						position,

Loading…
Отказ
Запис