Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eb1c5c6629 |
No files matched your search
@@ -1,2 +0,0 @@
|
|||||||
public class Bug422 {}
|
|
||||||
public class Bug422 {}
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import java.lang.Integer;
|
||||||
|
|
||||||
|
interface Bug423I { Integer f(); }
|
||||||
|
|
||||||
|
public class Bug423 implements Bug423I { }
|
||||||
@@ -15,6 +15,7 @@ interface C {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ClassX implements A {
|
class ClassX implements A {
|
||||||
|
void method1() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
record ClassY(Integer myInt) implements C {}
|
record ClassY(Integer myInt) implements C {}
|
||||||
|
|||||||
@@ -1846,6 +1846,35 @@ public class Codegen {
|
|||||||
clazz.constructors().forEach(this::generateConstructor);
|
clazz.constructors().forEach(this::generateConstructor);
|
||||||
clazz.methods().forEach(this::generateMethod);
|
clazz.methods().forEach(this::generateMethod);
|
||||||
|
|
||||||
|
// Check if non abstract class implements all interface methods
|
||||||
|
if ((access & ACC_ABSTRACT) == 0) {
|
||||||
|
for (var intf : clazz.implementingInterfaces()) {
|
||||||
|
var intfClass = compiler.getClass(new JavaClassName(intf.name()));
|
||||||
|
for (var method : intfClass.getMethods()) {
|
||||||
|
if ((method.modifier & ACC_ABSTRACT) != 0) {
|
||||||
|
// Check if the method is implemented in the current class
|
||||||
|
// TODO This is duplicate code, we should probably refactor instances of this pattern
|
||||||
|
var foundMethods = clazz.methods().stream().filter(m -> {
|
||||||
|
if (!m.name().equals(method.name)) return false;
|
||||||
|
if (m.signature().parameters().size() != method.getParameterList().getFormalparalist().size())
|
||||||
|
return false;
|
||||||
|
for (var i = 0; i < m.signature().parameters().size(); i++) {
|
||||||
|
var param1 = m.signature().parameters().get(i).pattern().type();
|
||||||
|
var param2 = converter.convert(
|
||||||
|
method.getParameterList().getParameterAt(i).getType(),
|
||||||
|
ASTToTargetAST.Generics.nullGenerics(compiler).javaGenerics());
|
||||||
|
if (!param1.equals(param2)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}).toList();
|
||||||
|
if (foundMethods.size() != 1) {
|
||||||
|
throw new CodeGenException("Class " + clazz.qualifiedName() + " does not implement method " + method.name + " from interface " + intfClass.getClassName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (clazz.staticConstructor() != null)
|
if (clazz.staticConstructor() != null)
|
||||||
generateStaticConstructor(clazz.staticConstructor());
|
generateStaticConstructor(clazz.staticConstructor());
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import de.dhbwstuttgart.bytecode.Codegen;
|
|||||||
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
import de.dhbwstuttgart.bytecode.FunNGenerator;
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
import de.dhbwstuttgart.environment.DirectoryClassLoader;
|
||||||
import de.dhbwstuttgart.exceptions.CompilerException;
|
|
||||||
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
import de.dhbwstuttgart.exceptions.CompilerWarning;
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
import de.dhbwstuttgart.exceptions.WarningsException;
|
import de.dhbwstuttgart.exceptions.WarningsException;
|
||||||
@@ -172,8 +171,6 @@ public class JavaTXCompiler {
|
|||||||
|
|
||||||
var numberOfGenerics = decl == null ? 0 : decl.genericTypeVar().size();
|
var numberOfGenerics = decl == null ? 0 : decl.genericTypeVar().size();
|
||||||
var className = pkgName + (!pkgName.isEmpty() ? "." : "") + name;
|
var className = pkgName + (!pkgName.isEmpty() ? "." : "") + name;
|
||||||
if (classRegistry.contains(className))
|
|
||||||
throw new CompilerException("Duplicate class definition: " + className);
|
|
||||||
classRegistry.addName(className, numberOfGenerics);
|
classRegistry.addName(className, numberOfGenerics);
|
||||||
input.add(classRegistry.getName(className));
|
input.add(classRegistry.getName(className));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package de.dhbwstuttgart.exceptions;
|
|
||||||
|
|
||||||
public class CompilerException extends RuntimeException {
|
|
||||||
public CompilerException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.CodeGenException;
|
import de.dhbwstuttgart.bytecode.CodeGenException;
|
||||||
import de.dhbwstuttgart.core.ConsoleInterface;
|
import de.dhbwstuttgart.core.ConsoleInterface;
|
||||||
import de.dhbwstuttgart.exceptions.CompilerException;
|
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
|
||||||
import de.dhbwstuttgart.exceptions.WarningsException;
|
import de.dhbwstuttgart.exceptions.WarningsException;
|
||||||
import de.dhbwstuttgart.util.Logger;
|
import de.dhbwstuttgart.util.Logger;
|
||||||
import de.dhbwstuttgart.util.Logger.LogLevel;
|
import de.dhbwstuttgart.util.Logger.LogLevel;
|
||||||
@@ -1708,12 +1706,12 @@ public class TestComplete {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBug422() throws Exception {
|
public void testBug423() throws Exception {
|
||||||
try {
|
try {
|
||||||
var classFiles = generateClassFiles(createClassLoader(), "Bug422.jav");
|
var classFiles = generateClassFiles(createClassLoader(), "Bug423.jav");
|
||||||
fail("Shouldn't compile!");
|
fail("No exception thrown!");
|
||||||
} catch (CompilerException e) {
|
} catch (CodeGenException e) {
|
||||||
assertEquals("Duplicate class definition: Bug422", e.getMessage());
|
assertEquals("Class Bug423 does not implement method f from interface Bug423I", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user