KT-529 wrong naming of anonimous classes
This commit is contained in:
@@ -224,7 +224,7 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
||||
|
||||
int i = 0;
|
||||
if (captureThis) {
|
||||
argTypes[i++] = Type.getObjectType(context.getThisDescriptor().getName());
|
||||
argTypes[i++] = state.getTypeMapper().mapType(context.getThisDescriptor().getDefaultType());
|
||||
}
|
||||
|
||||
if (captureReceiver != null) {
|
||||
|
||||
@@ -608,17 +608,20 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
|
||||
final Method cons = closure.getConstructor();
|
||||
|
||||
int k = 0;
|
||||
if (closure.isCaptureThis()) {
|
||||
k++;
|
||||
v.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||
}
|
||||
|
||||
if (closure.isCaptureReceiver() != null) {
|
||||
k++;
|
||||
v.load(context.getContextDescriptor().getContainingDeclaration() instanceof NamespaceDescriptor ? 0: 1, closure.isCaptureReceiver());
|
||||
}
|
||||
|
||||
for (int i = 0; i < closure.getArgs().size(); i++) {
|
||||
StackValue arg = closure.getArgs().get(i);
|
||||
arg.put(cons.getArgumentTypes()[i], v);
|
||||
arg.put(cons.getArgumentTypes()[i+k], v);
|
||||
}
|
||||
|
||||
v.invokespecial(closure.getClassname(), "<init>", cons.getDescriptor());
|
||||
|
||||
@@ -173,6 +173,11 @@ public class JetTypeMapper {
|
||||
|
||||
public String getFQName(DeclarationDescriptor descriptor) {
|
||||
descriptor = descriptor.getOriginal();
|
||||
|
||||
if(descriptor instanceof FunctionDescriptor) {
|
||||
return getFQName(descriptor.getContainingDeclaration());
|
||||
}
|
||||
|
||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||
String name = descriptor.getName();
|
||||
if(JetPsiUtil.NO_NAME_PROVIDED.equals(name)) {
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
namespace mask
|
||||
|
||||
import std.io.*
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
|
||||
fun box() : String {
|
||||
val input = StringReader("/Users/abreslav/work/jet/docs/luhnybin/src/test")
|
||||
|
||||
val luhny = Luhny()
|
||||
input.forEachChar {
|
||||
luhny.process(it)
|
||||
}
|
||||
luhny.printAll()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
class Luhny() {
|
||||
private val buffer = ArrayDeque<Char>()
|
||||
private val digits = ArrayDeque<Int>(16)
|
||||
|
||||
private var toBeMasked = 0
|
||||
|
||||
fun process(it : Char) {
|
||||
buffer.addLast(it)
|
||||
when (it) {
|
||||
.isDigit() => digits.addLast(it.int - '0'.int)
|
||||
' ', '-' => {}
|
||||
else => printAll()
|
||||
}
|
||||
if (digits.size() > 16)
|
||||
printOneDigit()
|
||||
check()
|
||||
}
|
||||
|
||||
private fun check() {
|
||||
val size = digits.size()
|
||||
if (size < 14) return
|
||||
val sum = digits.sum {i, d =>
|
||||
if (i % 2 == size % 2) double(d) else d
|
||||
}
|
||||
// var sum = 0
|
||||
// var i = 0
|
||||
// for (d in digits) {
|
||||
// sum += if (i % 2 == size % 2) double(d) else d
|
||||
// i++
|
||||
// }
|
||||
if (sum % 10 == 0) toBeMasked = digits.size()
|
||||
}
|
||||
|
||||
private fun double(d : Int) = d * 2 / 10 + d * 2 % 10
|
||||
|
||||
private fun printOneDigit() {
|
||||
while (!buffer.isEmpty()) {
|
||||
val c = buffer.removeFirst()
|
||||
print(c)
|
||||
if (c.isDigit()) {
|
||||
digits.removeFirst()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun printAll() {
|
||||
while (!buffer.isEmpty())
|
||||
print(buffer.removeFirst())
|
||||
digits.clear()
|
||||
}
|
||||
|
||||
private fun print(c : Char) {
|
||||
if (c.isDigit() && toBeMasked > 0) {
|
||||
std.io.print('X')
|
||||
toBeMasked--
|
||||
} else {
|
||||
std.io.print(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Char.isDigit() = Character.isDigit(this)
|
||||
|
||||
fun java.lang.Iterable<Int>.sum(f : fun(index : Int, value : Int) : Int) : Int {
|
||||
var sum = 0
|
||||
var i = 0
|
||||
for (d in this) {
|
||||
sum += f(i, d)
|
||||
i++
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
||||
do {
|
||||
var i = read();
|
||||
if (i == -1) break
|
||||
body(i.chr)
|
||||
} while(true)
|
||||
}
|
||||
@@ -77,4 +77,8 @@ public class StdlibTest extends CodegenTestCase {
|
||||
public void testKt533 () {
|
||||
blackBoxFile("regressions/kt533.kt");
|
||||
}
|
||||
|
||||
public void testKt529 () {
|
||||
blackBoxFile("regressions/kt529.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
namespace std
|
||||
|
||||
namespace util {
|
||||
import java.util.*
|
||||
|
||||
val <T> Collection<T>.size : Int
|
||||
get() = size()
|
||||
|
||||
val <T> Collection<T>.empty : Boolean
|
||||
get() = isEmpty()
|
||||
}
|
||||
|
||||
namespace io {
|
||||
import java.io.*
|
||||
import java.nio.charset.*
|
||||
|
||||
Reference in New Issue
Block a user