From 11ad28812d9fbb2785a8623e0f8baef18aa681cb Mon Sep 17 00:00:00 2001 From: svtk Date: Fri, 27 Jan 2012 18:28:54 +0400 Subject: [PATCH] KT-1175 Mark unused literals --- .../jet/lang/cfg/JetControlFlowProcessor.java | 2 +- .../lang/cfg/JetFlowInformationProvider.java | 33 +++++++++++ .../jet/lang/diagnostics/Errors.java | 2 + .../jetbrains/jet/lang/psi/JetPsiUtil.java | 57 ++++++++++++++++++- .../jet/lang/psi/JetVisitorVoid.java | 2 +- .../psi/JetWhenConditionWithExpression.java | 2 +- .../jet/lang/resolve/ControlFlowAnalyzer.java | 2 + .../PatternMatchingTypingVisitor.java | 2 +- .../diagnostics/tests/FunctionReturnTypes.jet | 2 +- .../tests/IncorrectCharacterLiterals.jet | 48 ++++++++-------- .../diagnostics/tests/StringTemplates.jet | 24 ++++---- .../diagnostics/tests/UnreachableCode.jet | 6 +- .../kt770.kt351.kt735_StatementType.jet | 2 +- .../tests/extensions/ExtensionFunctions.jet | 6 +- .../diagnostics/tests/infos/Autocasts.jet | 8 +-- .../diagnostics/tests/regressions/kt306.jet | 10 ++-- .../diagnostics/tests/regressions/kt402.jet | 2 +- .../diagnostics/tests/regressions/kt41.jet | 2 +- .../diagnostics/tests/regressions/kt847.jet | 2 +- .../ShadowParameterInNestedBlockInFor.jet | 4 +- .../shadowing/ShadowVariableInNestedBlock.jet | 6 +- .../ShadowVariableInNestedClosure.jet | 4 +- .../ShadowVariableInNestedClosureParam.jet | 4 +- idea/testData/checker/ExtensionFunctions.jet | 4 +- idea/testData/checker/StringTemplates.jet | 26 +++++---- idea/testData/checker/UnreachableCode.jet | 6 +- stdlib/ktSrc/Standard.kt | 4 ++ 27 files changed, 183 insertions(+), 89 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 3f7b24a8e21..c1ba50a53c1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -82,7 +82,7 @@ public class JetControlFlowProcessor { } @Override - public void visitWhenConditionExpression(JetWhenConditionWithExpression condition) { + public void visitWhenConditionWithExpression(JetWhenConditionWithExpression condition) { JetExpressionPattern pattern = condition.getPattern(); if (pattern != null) { pattern.accept(patternVisitor); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java index 32c775540ec..dd16bbc7f18 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetFlowInformationProvider.java @@ -641,6 +641,39 @@ public class JetFlowInformationProvider { } } +//////////////////////////////////////////////////////////////////////////////// +// "Unused literals" in block + + public void markUnusedLiteralsInBlock(@NotNull JetElement subroutine) { + Pseudocode pseudocode = pseudocodeMap.get(subroutine); + assert pseudocode != null; + JetControlFlowGraphTraverser traverser = JetControlFlowGraphTraverser.create(pseudocode, true, true); + traverser.traverseAndAnalyzeInstructionGraph(new JetControlFlowGraphTraverser.InstructionDataAnalyzeStrategy() { + @Override + public void execute(@NotNull Instruction instruction, @Nullable Void enterData, @Nullable Void exitData) { + if (!(instruction instanceof ReadValueInstruction)) return; + JetElement element = ((ReadValueInstruction) instruction).getElement(); + if (!(element instanceof JetFunctionLiteralExpression + || element instanceof JetConstantExpression + || element instanceof JetStringTemplateExpression + || element instanceof JetSimpleNameExpression)) { + return; + } + PsiElement parent = element.getParent(); + if (parent instanceof JetBlockExpression) { + if (!JetPsiUtil.isImplicitlyUsed(element)) { + if (element instanceof JetFunctionLiteralExpression) { + trace.report(Errors.UNUSED_FUNCTION_LITERAL.on((JetFunctionLiteralExpression) element)); + } + else { + trace.report(Errors.UNUSED_EXPRESSION.on(element)); + } + } + } + } + }); + } + //////////////////////////////////////////////////////////////////////////////// // Util methods 7 diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index e99ea7f7d38..8be2c6dffff 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -167,6 +167,8 @@ public interface Errors { return argument.getText(); } }; + SimpleDiagnosticFactory UNUSED_EXPRESSION = SimpleDiagnosticFactory.create(WARNING, "The expression is unused"); + SimplePsiElementOnlyDiagnosticFactory UNUSED_FUNCTION_LITERAL = SimplePsiElementOnlyDiagnosticFactory.create(WARNING, "The function literal is unused. If you mean block, you can use 'run { ... }'"); PsiElementOnlyDiagnosticFactory1 VAL_REASSIGNMENT = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Val can not be reassigned", NAME); PsiElementOnlyDiagnosticFactory1 INITIALIZATION_BEFORE_DECLARATION = PsiElementOnlyDiagnosticFactory1.create(ERROR, "Variable cannot be initialized before declaration", NAME); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index eb0f28d43a9..b1789879dd6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -1,12 +1,14 @@ package org.jetbrains.jet.lang.psi; import com.intellij.psi.PsiElement; +import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lexer.JetTokens; import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; /** @@ -85,11 +87,12 @@ public class JetPsiUtil { if (quoted.startsWith("`") && quoted.endsWith("`") && quoted.length() >= 2) { return quoted.substring(1, quoted.length() - 1); - } else { + } + else { return quoted; } } - + @NotNull public static String unquoteIdentifierOrFieldReference(@NotNull String quoted) { if (quoted.indexOf('`') < 0) { @@ -98,7 +101,8 @@ public class JetPsiUtil { if (quoted.startsWith("$")) { return "$" + unquoteIdentifier(quoted.substring(1)); - } else { + } + else { return unquoteIdentifier(quoted); } } @@ -167,4 +171,51 @@ public class JetPsiUtil { } return false; } + + @Nullable + public static T getDirectParentOfTypeForBlock(@NotNull JetBlockExpression block, @NotNull Class aClass) { + T parent = PsiTreeUtil.getParentOfType(block, aClass); + if (parent instanceof JetIfExpression) { + JetIfExpression ifExpression = (JetIfExpression) parent; + if (ifExpression.getElse() == block || ifExpression.getThen() == block) { + return parent; + } + } + if (parent instanceof JetWhenExpression) { + JetWhenExpression whenExpression = (JetWhenExpression) parent; + for (JetWhenEntry whenEntry : whenExpression.getEntries()) { + if (whenEntry.getExpression() == block) { + return parent; + } + } + } + if (parent instanceof JetFunctionLiteral) { + JetFunctionLiteral functionLiteral = (JetFunctionLiteral) parent; + if (functionLiteral.getBodyExpression() == block) { + return parent; + } + } + return null; + } + + public static boolean isImplicitlyUsed(@NotNull JetElement element) { + PsiElement parent = element.getParent(); + if (!(parent instanceof JetBlockExpression)) return true; + JetBlockExpression block = (JetBlockExpression) parent; + List statements = block.getStatements(); + if (statements.get(statements.size() - 1) == element) { + JetExpression expression = getDirectParentOfTypeForBlock(block, JetIfExpression.class); + if (expression == null) { + expression = getDirectParentOfTypeForBlock(block, JetWhenExpression.class); + } + if (expression == null) { + expression = getDirectParentOfTypeForBlock(block, JetFunctionLiteral.class); + } + if (expression != null) { + return isImplicitlyUsed(expression); + } + } + return false; + } + } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java index 4ec1b2284cc..5b9ba0db1c4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java @@ -358,7 +358,7 @@ public class JetVisitorVoid extends PsiElementVisitor { visitJetElement(condition); } - public void visitWhenConditionExpression(JetWhenConditionWithExpression condition) { + public void visitWhenConditionWithExpression(JetWhenConditionWithExpression condition) { visitJetElement(condition); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetWhenConditionWithExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetWhenConditionWithExpression.java index a3e4deb1854..62c9c67c520 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetWhenConditionWithExpression.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetWhenConditionWithExpression.java @@ -20,7 +20,7 @@ public class JetWhenConditionWithExpression extends JetWhenCondition { @Override public void accept(@NotNull JetVisitorVoid visitor) { - visitor.visitWhenConditionExpression(this); + visitor.visitWhenConditionWithExpression(this); } @Override diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java index 47bbf55705d..a6ddddc5f3b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/ControlFlowAnalyzer.java @@ -81,5 +81,7 @@ public class ControlFlowAnalyzer { flowInformationProvider.markUninitializedVariables(function.asElement(), context.isDeclaredLocally()); flowInformationProvider.markUnusedVariables(function.asElement()); + + flowInformationProvider.markUnusedLiteralsInBlock(function.asElement()); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java index c19b038fb98..bcd26f5eec1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java @@ -143,7 +143,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { } @Override - public void visitWhenConditionExpression(JetWhenConditionWithExpression condition) { + public void visitWhenConditionWithExpression(JetWhenConditionWithExpression condition) { JetPattern pattern = condition.getPattern(); if (pattern != null) { newDataFlowInfo[0] = checkPatternType(pattern, subjectType, subjectExpression == null, scopeToExtend, context, subjectVariables); diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.jet b/compiler/testData/diagnostics/tests/FunctionReturnTypes.jet index 11d8bcde513..79592722ab2 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.jet +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.jet @@ -36,7 +36,7 @@ fun intShortInfer() = 1 fun intShort() : Int = 1 //fun intBlockInfer() {1} fun intBlock() : Int {return 1} -fun intBlock1() : Int {1} +fun intBlock1() : Int {1} fun intString(): Int = "s" fun intFunctionLiteral(): Int = { 10 } diff --git a/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.jet b/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.jet index aee64608f0d..651bc3c479e 100644 --- a/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.jet +++ b/compiler/testData/diagnostics/tests/IncorrectCharacterLiterals.jet @@ -10,28 +10,28 @@ fun ff() { } fun test() { - 'a' - '\n' - '\t' - '\b' - '\r' - '\"' - '\'' - '\\' - '\$' - '\x' - '\123' - '\ra' - '\000' - '\000' - '\u0000' - '\u000a' - '\u000A' - '\u' - '\u0' - '\u00' - '\u000' - '\u000z' - '\\u000' - '\' + 'a' + '\n' + '\t' + '\b' + '\r' + '\"' + '\'' + '\\' + '\$' + '\x' + '\123' + '\ra' + '\000' + '\000' + '\u0000' + '\u000a' + '\u000A' + '\u' + '\u0' + '\u00' + '\u000' + '\u000z' + '\\u000' + '\' } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/StringTemplates.jet b/compiler/testData/diagnostics/tests/StringTemplates.jet index 976a06e3a02..1c6e67053c9 100644 --- a/compiler/testData/diagnostics/tests/StringTemplates.jet +++ b/compiler/testData/diagnostics/tests/StringTemplates.jet @@ -7,16 +7,16 @@ fun demo() { fun buzz(f : () -> Any?) : Int = 1 val sdf = 1 val foo = 3; - "$abc" - "$" - "$.$.asdf$\t" - "asd\$" - "asd$a\x" - "asd$a$asd$ $xxx" - "fosdfasdo${1 + bar + 100}}sdsdfgdsfsdf" - "foo${bar + map {foo}}sdfsdf" - "foo${bar + map { "foo" }}sdfsdf" - "foo${bar + map { - "foo$sdf${ buzz{}}" }}sdfsdf" - "a\u \u0 \u00 \u000 \u0000 \u0AaA \u0AAz.length( ) + \u0022b" + "$abc" + "$" + "$.$.asdf$\t" + "asd\$" + "asd$a\x" + "asd$a$asd$ $xxx" + "fosdfasdo${1 + bar + 100}}sdsdfgdsfsdf" + "foo${bar + map {foo}}sdfsdf" + "foo${bar + map { "foo" }}sdfsdf" + "foo${bar + map { + "foo$sdf${ buzz{}}" }}sdfsdf" + "a\u \u0 \u00 \u000 \u0000 \u0AaA \u0AAz.length( ) + \u0022b" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/UnreachableCode.jet b/compiler/testData/diagnostics/tests/UnreachableCode.jet index f8a4062984e..6352778d4c6 100644 --- a/compiler/testData/diagnostics/tests/UnreachableCode.jet +++ b/compiler/testData/diagnostics/tests/UnreachableCode.jet @@ -110,7 +110,7 @@ fun t7() : Int { 2 } catch (e : Any) { - 2 + 2 } return 1 // this is OK, like in Java } @@ -145,8 +145,8 @@ fun failtest(a : Int) : Int { } fun foo(a : Nothing) : Unit { - 1 - a + 1 + a 2 } diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.jet b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.jet index 878cce20769..50a52f77d22 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.jet +++ b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.jet @@ -62,7 +62,7 @@ fun testCoercionToUnit() { when(i) { is 1 -> { val d = 34 - "1" + "1" doSmth(d) } diff --git a/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.jet b/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.jet index 6d2596c7c65..d68d7c8cb7d 100644 --- a/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.jet +++ b/compiler/testData/diagnostics/tests/extensions/ExtensionFunctions.jet @@ -22,11 +22,11 @@ fun A.plus(a : Any) { 1.foo() true.foo() - 1 + 1 } fun A.plus(a : Int) { - 1 + 1 } fun T.minus(t : T) : Int = 1 @@ -73,4 +73,4 @@ import outer.* c?.equals2(null) if (command == null) 1 - } + } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/infos/Autocasts.jet b/compiler/testData/diagnostics/tests/infos/Autocasts.jet index 3b92d238d76..b1ccca9bc15 100644 --- a/compiler/testData/diagnostics/tests/infos/Autocasts.jet +++ b/compiler/testData/diagnostics/tests/infos/Autocasts.jet @@ -116,12 +116,12 @@ fun f13(a : A?) { } if (!(a is val c is B) || !(a is val x is C)) { - x - c + x + c } else { - x - c + x + c } if (!(a is val c is B) || !(a is val c is C)) { diff --git a/compiler/testData/diagnostics/tests/regressions/kt306.jet b/compiler/testData/diagnostics/tests/regressions/kt306.jet index cb4a4f182f5..b1d59eceac1 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt306.jet +++ b/compiler/testData/diagnostics/tests/regressions/kt306.jet @@ -1,16 +1,16 @@ // KT-306 Ambiguity when different this's have same-looking functions fun test() { - {Foo.() -> + {Foo.() -> bar(); {Barr.() -> this.bar() bar() } - } - {Barr.() -> + } + {Barr.() -> bar() - } + } } class Foo { @@ -19,4 +19,4 @@ class Foo { class Barr { fun bar() {} -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt402.jet b/compiler/testData/diagnostics/tests/regressions/kt402.jet index a1e70b417f2..a1a83723e34 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt402.jet +++ b/compiler/testData/diagnostics/tests/regressions/kt402.jet @@ -1,7 +1,7 @@ package kt402 fun getTypeChecker() : (Any)->Boolean { - { (a : Any) -> a is T } // reports unsupported + { (a : Any) -> a is T } // reports unsupported } fun f() : (Any) -> Boolean { return { (a : Any) -> a is String } diff --git a/compiler/testData/diagnostics/tests/regressions/kt41.jet b/compiler/testData/diagnostics/tests/regressions/kt41.jet index 91e93881f06..e8ace3901ad 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt41.jet +++ b/compiler/testData/diagnostics/tests/regressions/kt41.jet @@ -7,5 +7,5 @@ fun aaa() = fun bbb() { aaa() - 1 // Stupid error: unreachable code + 1 // Stupid error: unreachable code } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt847.jet b/compiler/testData/diagnostics/tests/regressions/kt847.jet index 4d696af9910..e62c3076d51 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt847.jet +++ b/compiler/testData/diagnostics/tests/regressions/kt847.jet @@ -1,3 +1,3 @@ fun T.mustBe(t : T) { - "$this must be$as$t" + "$this must be$as$t" } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.jet b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.jet index 303434c77a1..fa42b9741a3 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.jet +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowParameterInNestedBlockInFor.jet @@ -1,7 +1,7 @@ fun f(i: Int) { for (j in 1..100) { - { + { var i = 12 - } + } } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.jet b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.jet index 2fd755bdc1c..bd767e82afc 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.jet +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedBlock.jet @@ -1,7 +1,7 @@ fun ff(): Int { var i = 1 - { + { val i = 2 - } + } return i -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.jet b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.jet index e448f74f8c9..e6d6b19b199 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.jet +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosure.jet @@ -1,5 +1,5 @@ fun f(): Int { var i = 17 - { (): Unit -> var i = 18 } + { (): Unit -> var i = 18 } return i -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.jet b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.jet index d926e4bca41..6939a528400 100644 --- a/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.jet +++ b/compiler/testData/diagnostics/tests/shadowing/ShadowVariableInNestedClosureParam.jet @@ -1,5 +1,5 @@ fun ff(): Int { var i = 1 - { (i: Int) -> i } + { (i: Int) -> i } return i -} +} \ No newline at end of file diff --git a/idea/testData/checker/ExtensionFunctions.jet b/idea/testData/checker/ExtensionFunctions.jet index f2a2d18ed0c..934636e0b6d 100644 --- a/idea/testData/checker/ExtensionFunctions.jet +++ b/idea/testData/checker/ExtensionFunctions.jet @@ -18,11 +18,11 @@ fun A.plus(a : Any) { 1.foo() true.foo() - 1 + 1 } fun A.plus(a : Int) { - 1 + 1 } fun T.minus(t : T) : Int = 1 diff --git a/idea/testData/checker/StringTemplates.jet b/idea/testData/checker/StringTemplates.jet index ab2b794ceb6..236c7a4f0ef 100644 --- a/idea/testData/checker/StringTemplates.jet +++ b/idea/testData/checker/StringTemplates.jet @@ -7,15 +7,17 @@ fun demo() { fun buzz(f : () -> Any?) : Int = 1 val sdf = 1 val foo = 3; - "$abc" - "$" - "$.$.asdf$\t" - "asd\$" - "asd$a\x" - "asd$a$asd$ $xxx" - "fosdfasdo${1 + bar + 100}}sdsdfgdsfsdf" - "foo${bar + map {foo}}sdfsdf" - "foo${bar + map { "foo" }}sdfsdf" - "foo${bar + map { - "foo$sdf${ buzz{}}" }}sdfsdf" -} \ No newline at end of file + use("$abc") + use("$") + use("$.$.asdf$\t") + use("asd\$") + use("asd$a\x") + use("asd$a$asd$ $xxx") + use("fosdfasdo${1 + bar + 100}}sdsdfgdsfsdf") + use("foo${bar + map {foo}}sdfsdf") + use("foo${bar + map { "foo" }}sdfsdf") + use("foo${bar + map { + "foo$sdf${ buzz{}}" }}sdfsdf") +} + +fun use(s: String) {} \ No newline at end of file diff --git a/idea/testData/checker/UnreachableCode.jet b/idea/testData/checker/UnreachableCode.jet index bec6501b754..d6a6eab78ba 100644 --- a/idea/testData/checker/UnreachableCode.jet +++ b/idea/testData/checker/UnreachableCode.jet @@ -108,7 +108,7 @@ fun t7() : Int { 2 } catch (e : Any) { - 2 + 2 } return 1 // this is OK, like in Java } @@ -143,8 +143,8 @@ fun failtest(a : Int) : Int { } fun foo(a : Nothing) : Unit { - 1 - a + 1 + a 2 } diff --git a/stdlib/ktSrc/Standard.kt b/stdlib/ktSrc/Standard.kt index 132c3ae89e2..46dfa65f5dc 100644 --- a/stdlib/ktSrc/Standard.kt +++ b/stdlib/ktSrc/Standard.kt @@ -65,3 +65,7 @@ Add iterated elements to java.util.TreeSet */ inline fun Iterator.toTreeSet() = to(TreeSet()) +/* +Run function f +*/ +inline fun run(f: () -> T) = f() \ No newline at end of file