Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -5,15 +5,15 @@ namespace a {
|
||||
}
|
||||
|
||||
namespace b {
|
||||
fun foo() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!>
|
||||
fun foo() = bar()
|
||||
|
||||
fun bar() = foo()
|
||||
fun bar() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>foo()<!>
|
||||
}
|
||||
|
||||
namespace c {
|
||||
fun bazz() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!>
|
||||
fun bazz() = bar()
|
||||
|
||||
fun foo() = bazz()
|
||||
fun foo() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bazz()<!>
|
||||
|
||||
fun bar() = foo()
|
||||
}
|
||||
@@ -39,4 +39,4 @@ namespace ok {
|
||||
|
||||
fun bar() = foo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
// KT-588 Unresolved static method
|
||||
class Test() : Thread("Test") {
|
||||
class object {
|
||||
fun init2() {
|
||||
|
||||
}
|
||||
}
|
||||
override fun run() {
|
||||
init2() // unresolved
|
||||
Test.init2() // ok
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun bar() = {
|
||||
<!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun bar() = {
|
||||
fun foo() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// http://youtrack.jetbrains.net/issue/KT-329
|
||||
|
||||
fun block(f : fun() : Unit) = f()
|
||||
|
||||
fun bar() = block{ <!UNRESOLVED_REFERENCE!>foo<!>() // <-- missing closing curly bracket
|
||||
fun foo() = block{ <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>bar()<!> }
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-394 Make class object members visible inside the owning class
|
||||
|
||||
class X() {
|
||||
// class Y {}
|
||||
|
||||
class object{
|
||||
class Y() {}
|
||||
}
|
||||
|
||||
val y : Y = Y()
|
||||
}
|
||||
@@ -1,16 +1,7 @@
|
||||
import std.io.*
|
||||
|
||||
import java.io.*
|
||||
|
||||
val ByteArray.inputStream : ByteArrayInputStream
|
||||
get() = ByteArrayInputStream(this)
|
||||
|
||||
fun InputStream.iterator() : ByteIterator =
|
||||
object: ByteIterator() {
|
||||
override val hasNext : Boolean
|
||||
get() = available() > 0
|
||||
|
||||
override fun nextByte() = read().byt
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val x = ByteArray (10)
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
namespace mask
|
||||
|
||||
import std.io.*
|
||||
import java.io.*
|
||||
import java.util.*
|
||||
import java.util.Iterator as It
|
||||
import java.lang.Iterable as Itl
|
||||
|
||||
fun box() : String {
|
||||
val input = StringReader("/Users/abreslav/work/jet/docs/luhnybin/src/test")
|
||||
|
||||
val luhny = Luhny()
|
||||
input.forEachChar {
|
||||
luhny.charIn(it)
|
||||
}
|
||||
luhny.printAll()
|
||||
return "OK"
|
||||
}
|
||||
|
||||
class Luhny() {
|
||||
val buffer = LinkedList<Char>()
|
||||
val digits = LinkedList<Int>()
|
||||
|
||||
var toBeMasked = 0
|
||||
|
||||
fun charIn(it : Char) {
|
||||
buffer.addLast(it)
|
||||
when (it) {
|
||||
.isDigit() => digits.addLast(it.int - '0'.int)
|
||||
' ', '-' => {}
|
||||
else => {
|
||||
printAll()
|
||||
digits.clear()
|
||||
}
|
||||
}
|
||||
if (digits.size() > 16)
|
||||
printOneDigit()
|
||||
check()
|
||||
}
|
||||
|
||||
fun check() {
|
||||
if (digits.size() < 14) return
|
||||
print("check")
|
||||
val sum = digits.sum { i, d =>
|
||||
// println("$i -> $d")
|
||||
if (i % 2 == digits.size()) {
|
||||
val f = d * 2 / 10
|
||||
val s = d * 2 % 10
|
||||
// println("$d: f = $f, s = $s")
|
||||
(f + s).pr {
|
||||
// println("to be doubled: $i -> $d : $it")
|
||||
}
|
||||
} else d
|
||||
}
|
||||
// println(sum)
|
||||
if (sum % 10 == 0) {print("s"); toBeMasked = digits.size()}
|
||||
}
|
||||
|
||||
fun printOneDigit() {
|
||||
while (!buffer.isEmpty()) {
|
||||
val c = buffer.removeFirst()
|
||||
out(c)
|
||||
if (c.isDigit()) {
|
||||
digits.removeFirst()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun printAll() {
|
||||
while (!buffer.isEmpty())
|
||||
out(buffer.removeFirst())
|
||||
}
|
||||
|
||||
fun out(c : Char) {
|
||||
if (toBeMasked > 0) {
|
||||
print('X')
|
||||
toBeMasked--
|
||||
}
|
||||
else {
|
||||
print(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> T.pr(f : fun(T) : Unit) : T {
|
||||
f(this)
|
||||
return this
|
||||
}
|
||||
|
||||
fun LinkedList<Int>.sum(f : fun(Int, Int ): Int): Int {
|
||||
var sum = 0
|
||||
for (i in 1..size()) {
|
||||
val j = size() - i
|
||||
sum += f(j, get(j))
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
//fun <T> List<T>.backwards() : Itl<T> = object : Itl<T> {
|
||||
// override fun iterator() : It<T> =
|
||||
// object : It<T> {
|
||||
// var current = size()
|
||||
// override fun next() : T = get(--current)
|
||||
// override fun hasNext() : Boolean = current > 0
|
||||
// override fun remove() {throw UnsupportedOperationException()}
|
||||
// }
|
||||
//}
|
||||
|
||||
fun Char.isDigit() = Character.isDigit(this)
|
||||
|
||||
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
||||
do {
|
||||
var i = read();
|
||||
if (i == -1) break
|
||||
body(i.chr)
|
||||
} while(true)
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
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.charIn(it)
|
||||
}
|
||||
luhny.printAll()
|
||||
return "OK"
|
||||
|
||||
}
|
||||
|
||||
class Luhny() {
|
||||
val buffer = LinkedList<Char>()
|
||||
val digits = LinkedList<Int>()
|
||||
|
||||
var toBeMasked = 0
|
||||
|
||||
fun charIn(it : Char) {
|
||||
buffer.push(it)
|
||||
when (it) {
|
||||
.isDigit() => digits.push(it.int - '0'.int)
|
||||
' ', '-' => {}
|
||||
else => {
|
||||
printAll()
|
||||
digits.clear()
|
||||
}
|
||||
}
|
||||
if (digits.size() > 16)
|
||||
printOneDigit()
|
||||
check()
|
||||
}
|
||||
|
||||
fun check() {
|
||||
if (digits.size() < 14) return
|
||||
val sum = digits.sum { i, d =>
|
||||
if (i % 2 != 0)
|
||||
d * 2 / 10 + d * 2 % 10
|
||||
else d
|
||||
}
|
||||
if (sum % 10 == 0) toBeMasked = digits.size()
|
||||
}
|
||||
|
||||
fun printOneDigit() {
|
||||
while (!buffer.isEmpty()) {
|
||||
val c = buffer.pop()
|
||||
out(c)
|
||||
if (c.isDigit()) {
|
||||
digits.pop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun printAll() {
|
||||
while (!buffer.isEmpty())
|
||||
out(buffer.pop())
|
||||
}
|
||||
|
||||
fun out(c : Char) {
|
||||
if (toBeMasked > 0) {
|
||||
print('X')
|
||||
toBeMasked--
|
||||
}
|
||||
else {
|
||||
print(c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun LinkedList<Int>.sum(f : fun(Int, Int) : Int) : Int {
|
||||
var sum = 0
|
||||
var i = 0
|
||||
for (d in backwards()) {
|
||||
sum += f(i, d)
|
||||
i++
|
||||
}
|
||||
return sum
|
||||
}
|
||||
|
||||
fun <T> List<T>.backwards() : Iterable<T> = object : Iterable<T> {
|
||||
override fun iterator() : Iterator<T> =
|
||||
object : Iterator<T> {
|
||||
var current = size()
|
||||
override fun next() : T = get(--current)
|
||||
override val hasNext : Boolean get() = current > 0
|
||||
}
|
||||
}
|
||||
|
||||
fun Char.isDigit() = Character.isDigit(this)
|
||||
|
||||
//class Queue<T>(initialBufSize : Int) {
|
||||
//
|
||||
// private var bufSize = initialBufSize
|
||||
// private val buf = Array<T>(initialBufSize)
|
||||
// private var head = 0
|
||||
// private var tail = 0
|
||||
// private var size = 0
|
||||
//
|
||||
// val empty : Boolean get() = size == 0
|
||||
//
|
||||
// private fun prev(i : Int) = (bufSize + i - 1) % bufSize
|
||||
// private fun next(i : Int) = (i + 1) % bufSize
|
||||
//
|
||||
// fun push(c : T) {
|
||||
// buf[tail] = c
|
||||
// tail = prev(tail)
|
||||
// size++
|
||||
// }
|
||||
//
|
||||
// fun pop() : T {
|
||||
// if (size == 0) throw IllegalStateException()
|
||||
// size--
|
||||
// val result = buf[head]
|
||||
// head = prev(head)
|
||||
// return result
|
||||
// }
|
||||
//
|
||||
// fun clear() {}
|
||||
//}
|
||||
|
||||
fun Reader.forEachChar(body : fun(Char) : Unit) {
|
||||
do {
|
||||
var i = read();
|
||||
if (i == -1) break
|
||||
body(i.chr)
|
||||
} while(true)
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace array_test
|
||||
|
||||
fun box() : String {
|
||||
var array : IntArray? = IntArray(10)
|
||||
array?.set(0, 3)
|
||||
if(array?.get(0) != 3) return "fail"
|
||||
|
||||
var a = Array<Array<String?>?>(5)
|
||||
var b = Array<String?>(1)
|
||||
b.set(0, "239")
|
||||
a?.set(0, b)
|
||||
|
||||
if(a?.get(0)?.get(0) != "239") return "fail"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user