Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6c59f07f6 |
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
public class Bug422 {}
|
||||||
|
public class Bug422 {}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import java.lang.Integer;
|
|
||||||
|
|
||||||
interface Bug423I { Integer f(); }
|
|
||||||
|
|
||||||
public class Bug423 implements Bug423I { }
|
|
||||||
@@ -15,7 +15,6 @@ 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,35 +1846,6 @@ 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,6 +5,7 @@ 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;
|
||||||
@@ -171,6 +172,8 @@ 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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package de.dhbwstuttgart.exceptions;
|
||||||
|
|
||||||
|
public class CompilerException extends RuntimeException {
|
||||||
|
public CompilerException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
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;
|
||||||
@@ -1706,12 +1708,12 @@ public class TestComplete {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBug423() throws Exception {
|
public void testBug422() throws Exception {
|
||||||
try {
|
try {
|
||||||
var classFiles = generateClassFiles(createClassLoader(), "Bug423.jav");
|
var classFiles = generateClassFiles(createClassLoader(), "Bug422.jav");
|
||||||
fail("No exception thrown!");
|
fail("Shouldn't compile!");
|
||||||
} catch (CodeGenException e) {
|
} catch (CompilerException e) {
|
||||||
assertEquals("Class Bug423 does not implement method f from interface Bug423I", e.getMessage());
|
assertEquals("Duplicate class definition: Bug422", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user