diff --git a/compiler/testData/codegen/box/primitiveTypes/kt2768.kt b/compiler/testData/codegen/box/primitiveTypes/kt2768.kt new file mode 100644 index 00000000000..63aa44ded32 --- /dev/null +++ b/compiler/testData/codegen/box/primitiveTypes/kt2768.kt @@ -0,0 +1,17 @@ +fun assertEquals(a: T, b: T) { + if (a != b) throw AssertionError("$a != $b") +} + +fun box(): String { + val bytePos = 128.toByte() // Byte.MAX_VALUE + 1 + assertEquals(-128, bytePos.toInt()) // correct, wrapped to Byte.MIN_VALUE + + val shortPos = 32768.toShort() // Short.MAX_VALUE + 1 + assertEquals(-32768, shortPos.toInt()) // correct, wrapped to Short.MIN_VALUE + + assertEquals((-128).toByte().toString(), "-128") + // TODO: KT-2780 + // assertEquals((-128.toByte()).toString(), "-128") + + return "OK" +} diff --git a/compiler/testData/codegen/box/strings/kt2592.kt b/compiler/testData/codegen/box/strings/kt2592.kt new file mode 100644 index 00000000000..013ad56f0d6 --- /dev/null +++ b/compiler/testData/codegen/box/strings/kt2592.kt @@ -0,0 +1,4 @@ +fun box(): String { + String() + return String() + "OK" + String() +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt2768.kt b/compiler/testData/diagnostics/tests/regressions/kt2768.kt new file mode 100644 index 00000000000..dee6f36065e --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt2768.kt @@ -0,0 +1,20 @@ +fun assertEquals(a: T, b: T) { + if (a != b) throw AssertionError("$a != $b") +} + +fun main(args: Array) { + val bytePos = 128.toByte() // Byte.MAX_VALUE + 1 + assertEquals(-128, bytePos.toInt()) // correct, wrapped to Byte.MIN_VALUE + + val byteNeg: Byte = -bytePos // should not compile, byteNeg should be Int + assertEquals(128, byteNeg.toInt()) // passes, should not be possible + + val shortPos = 32768.toShort() // Short.MAX_VALUE + 1 + assertEquals(-32768, shortPos.toInt()) // correct, wrapped to Short.MIN_VALUE + + val shortNeg: Short = -shortPos // should not compile, shortNeg should be Int + assertEquals(32768, shortNeg.toInt()) // passes, should not be possible + + (-128).toByte() + -128.toByte() +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 75a3ed7d6a8..5d83b0d17ae 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -5613,6 +5613,11 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/regressions/kt26-1.kt"); } + @TestMetadata("kt2768.kt") + public void testKt2768() throws Exception { + doTest("compiler/testData/diagnostics/tests/regressions/kt2768.kt"); + } + @TestMetadata("kt282.kt") public void testKt282() throws Exception { doTest("compiler/testData/diagnostics/tests/regressions/kt282.kt"); diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index 10dc59db4ba..9119d80112a 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -4336,6 +4336,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/primitiveTypes/kt248.kt"); } + @TestMetadata("kt2768.kt") + public void testKt2768() throws Exception { + doTest("compiler/testData/codegen/box/primitiveTypes/kt2768.kt"); + } + @TestMetadata("kt2794.kt") public void testKt2794() throws Exception { doTest("compiler/testData/codegen/box/primitiveTypes/kt2794.kt"); @@ -4786,6 +4791,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest("compiler/testData/codegen/box/strings/ea35743.kt"); } + @TestMetadata("kt2592.kt") + public void testKt2592() throws Exception { + doTest("compiler/testData/codegen/box/strings/kt2592.kt"); + } + @TestMetadata("kt3652.kt") public void testKt3652() throws Exception { doTest("compiler/testData/codegen/box/strings/kt3652.kt");