Prechádzať zdrojové kódy

fix: type deduction

Ranides Atterwim 10 rokov pred
rodič
commit
3399fcff66

+ 3 - 0
assira.junit/src/main/java/net/ranides/assira/junit/TestContractRunner.java

@@ -166,6 +166,9 @@ public final class TestContractRunner {
 			type = supplier.get().getClass();
 		} else {
 			type = TestUtils.typeof(function);
+			if(debug) {
+				output.printf("Function is used for type deduction. Result: %s%n", type);
+			}
 		}
         ICounter counter = new ICounter();
         List<String> failed = new ArrayList<>();

+ 10 - 2
assira.junit/src/main/java/net/ranides/assira/junit/TestUtils.java

@@ -59,6 +59,13 @@ final class TestUtils {
 	}
 	
 	private static Class<?> typeof_lambda(Function<?,?> function) {
+		// Masakra, jeśli lambda jest closure'm, to jej "metoda" pobiera więcej niż 1 argument.
+		// Te argumenty są "bindowane" przez inne metody-gettery pomocnicze.
+		//
+		// Dałoby się te argumenty ignorować "mądrze", bo są listowane w ConstantPool,
+		// ale na razie po prostu weźmy pierwsze "coś", które ma więcej niż 1 argument
+		// i módlmy się, żeby to nie było żadne syntetyczne gówno.
+		
 		ConstantPool cp = Li.get(function.getClass());
 		
 		for(int i=0; i<cp.getSize(); i++) {
@@ -70,11 +77,12 @@ final class TestUtils {
 			}
 			
 			String parent = info[0];
-			if("java/lang/Object".equals(parent) || "java/lang/Class".equals(parent)) {
+			String name = info[1];
+			if("java/lang/Object".equals(parent) || "java/lang/Class".equals(parent) || "<init>".equals(name)) {
 				continue;
 			}
 			try {
-				if(1 != net.ranides.asm.Type.getArgumentTypes(info[2]).length) {
+				if(net.ranides.asm.Type.getArgumentTypes(info[2]).length < 1) {
 					continue;
 				}
 			} catch(Exception ex) {