diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/WhenChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/WhenChecker.kt index b65f2ebfa4f..dc74adb98e0 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/WhenChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/WhenChecker.kt @@ -398,6 +398,6 @@ object WhenChecker { } fun checkReservedPrefix(trace: BindingTrace, expression: KtWhenExpression) { - checkReservedPrefixWord(trace, expression.whenKeyword, "sealed", TokenSet.EMPTY, "sealed when") + checkReservedPrefixWord(trace, expression.whenKeyword, "sealed", "sealed when") } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/lexer/KtTokens.java b/compiler/frontend/src/org/jetbrains/kotlin/lexer/KtTokens.java index 1b9be2c2646..5f4f2ca47ab 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/lexer/KtTokens.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/lexer/KtTokens.java @@ -251,11 +251,6 @@ public interface KtTokens { NOT_IN, NOT_IS, IDENTIFIER); - TokenSet BINARY_OPERATIONS = TokenSet.create(AS_KEYWORD, AS_SAFE, IS_KEYWORD, IN_KEYWORD, MUL, PLUS, - MINUS, DIV, PERC, LT, GT, LTEQ, GTEQ, EQEQEQ, EXCLEQEQEQ, EQEQ, EXCLEQ, ANDAND, OROR, - ELVIS, RANGE, EQ, MULTEQ, DIVEQ, PERCEQ, PLUSEQ, MINUSEQ, - NOT_IN, NOT_IS); - TokenSet AUGMENTED_ASSIGNMENTS = TokenSet.create(PLUSEQ, MINUSEQ, MULTEQ, PERCEQ, DIVEQ); TokenSet ALL_ASSIGNMENTS = TokenSet.create(EQ, PLUSEQ, MINUSEQ, MULTEQ, PERCEQ, DIVEQ); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java index 723382be91b..51d990be07e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiUtil.java @@ -24,7 +24,6 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiWhiteSpace; import com.intellij.psi.tree.IElementType; -import com.intellij.psi.tree.TokenSet; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.util.codeInsight.CommentUtilCore; import org.jetbrains.annotations.Contract; @@ -598,21 +597,9 @@ public class KtPsiUtil { return prev; } - /** - * Example: - * code: async* {} - * element = "{}" - * word = "async" - * suffixTokens = [+, -, *, /, %] - * - * result = async - */ @Nullable - public static PsiElement getPreviousWord(@NotNull PsiElement element, @NotNull String word, @NotNull TokenSet suffixTokens) { + public static PsiElement getPreviousWord(@NotNull PsiElement element, @NotNull String word) { PsiElement prev = prevLeafIgnoringWhitespaceAndComments(element); - if (prev != null && suffixTokens.contains(prev.getNode().getElementType())) { - prev = PsiTreeUtil.prevLeaf(prev, false); - } if (prev != null && prev.getNode().getElementType() == KtTokens.IDENTIFIER && word.equals(prev.getText())) { return prev; } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt index b5f03667165..d95864ea06c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/psiUtil/ktPsiUtil.kt @@ -448,8 +448,8 @@ fun canPlaceAfterSimpleNameEntry(element: PsiElement?): Boolean { return !BAD_NEIGHBOUR_FOR_SIMPLE_TEMPLATE_ENTRY_PATTERN.matches(entryText) } -fun checkReservedPrefixWord(sink: DiagnosticSink, element: PsiElement, word: String, suffixTokens: TokenSet, message: String) { - KtPsiUtil.getPreviousWord(element, word, suffixTokens)?.let { +fun checkReservedPrefixWord(sink: DiagnosticSink, element: PsiElement, word: String, message: String) { + KtPsiUtil.getPreviousWord(element, word)?.let { sink.report(Errors.UNSUPPORTED.on(it, message)) } } @@ -458,4 +458,4 @@ fun KtElement.nonStaticOuterClasses(): Sequence { return generateSequence(containingClass()) { if (it.isInner()) it.containingClass() else null } } -fun KtElement.containingClass(): KtClass? = getStrictParentOfType() \ No newline at end of file +fun KtElement.containingClass(): KtClass? = getStrictParentOfType() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt index 7baccba0813..751d5b93381 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/FunctionsTypingVisitor.kt @@ -160,7 +160,7 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre } private fun checkReservedAsync(context: ExpressionTypingContext, expression: PsiElement) { - checkReservedPrefixWord(context.trace, expression, "async", KtTokens.BINARY_OPERATIONS, "async block/lambda. Use 'async() { ... }' or 'async(fun...)'") + checkReservedPrefixWord(context.trace, expression, "async", "async block/lambda. Use 'async() { ... }' or 'async(fun...)'") } private fun createFunctionLiteralDescriptor( diff --git a/compiler/testData/diagnostics/tests/ReservedAsync.kt b/compiler/testData/diagnostics/tests/ReservedAsync.kt index 0072cb6827f..f14e04ac806 100644 --- a/compiler/testData/diagnostics/tests/ReservedAsync.kt +++ b/compiler/testData/diagnostics/tests/ReservedAsync.kt @@ -20,26 +20,4 @@ fun test(foo: Any) { foo async (fun () {}) async (fun () {}) -} - -object async { - operator fun plus(f: () -> Unit) = f() - operator fun minus(f: () -> Unit) = f() - operator fun times(f: () -> Unit) = f() - operator fun div(f: () -> Unit) = f() - operator fun mod(f: () -> Unit) = f() -} - -fun test() { - async+ {} - async- {} - async* {} - async/ {} - async% {} - - async + {} - async - {} - async * {} - async / {} - async % {} } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/ReservedAsync.txt b/compiler/testData/diagnostics/tests/ReservedAsync.txt index bdf3fe84a85..8f9046d89b8 100644 --- a/compiler/testData/diagnostics/tests/ReservedAsync.txt +++ b/compiler/testData/diagnostics/tests/ReservedAsync.txt @@ -1,18 +1,5 @@ package public fun async(/*0*/ f: () -> kotlin.Unit): kotlin.Unit -public fun test(): kotlin.Unit public fun test(/*0*/ foo: kotlin.Any): kotlin.Unit public infix fun kotlin.Any.async(/*0*/ f: () -> kotlin.Unit): kotlin.Unit - -public object async { - private constructor async() - public final operator fun div(/*0*/ f: () -> kotlin.Unit): kotlin.Unit - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public final operator fun minus(/*0*/ f: () -> kotlin.Unit): kotlin.Unit - public final operator fun mod(/*0*/ f: () -> kotlin.Unit): kotlin.Unit - public final operator fun plus(/*0*/ f: () -> kotlin.Unit): kotlin.Unit - public final operator fun times(/*0*/ f: () -> kotlin.Unit): kotlin.Unit - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/UnsupportedAsyncFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/UnsupportedAsyncFix.kt index 0537c2819be..590e96aef7a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/UnsupportedAsyncFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/UnsupportedAsyncFix.kt @@ -23,7 +23,6 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.idea.codeInsight.surroundWith.expression.KotlinParenthesesSurrounder -import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtBinaryExpression import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtFile @@ -34,15 +33,8 @@ class UnsupportedAsyncFix(val psiElement: PsiElement): KotlinQuickFixAction Unit) {} infix fun Any.async(f: () -> Unit) {} -object async { - operator fun times(f: () -> Unit) = f() -} fun test(foo: Any) { async { } @@ -95,7 +92,5 @@ fun test(foo: Any) { foo async (fun () {}) async (fun () {}) - - async* {} } diff --git a/idea/testData/inspections/cleanup/cleanup.kt.after b/idea/testData/inspections/cleanup/cleanup.kt.after index 642b8c0b208..6f4915b481b 100644 --- a/idea/testData/inspections/cleanup/cleanup.kt.after +++ b/idea/testData/inspections/cleanup/cleanup.kt.after @@ -76,9 +76,6 @@ fun infixTest() { fun async(f: () -> Unit) {} infix fun Any.async(f: () -> Unit) {} -object async { - operator fun times(f: () -> Unit) = f() -} fun test(foo: Any) { async() { } @@ -94,7 +91,5 @@ fun test(foo: Any) { foo async (fun () {}) async (fun () {}) - - async * {} } diff --git a/idea/testData/quickfix/asyncUnsupported/asyncWithTimes.kt b/idea/testData/quickfix/asyncUnsupported/asyncWithTimes.kt deleted file mode 100644 index f766d113331..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncWithTimes.kt +++ /dev/null @@ -1,8 +0,0 @@ -// "Migrate unsupported async syntax" "true" -object async { - operator fun times(f: () -> Unit) = f() -} - -fun test() { - async* { } -} diff --git a/idea/testData/quickfix/asyncUnsupported/asyncWithTimes.kt.after b/idea/testData/quickfix/asyncUnsupported/asyncWithTimes.kt.after deleted file mode 100644 index 3c51c5b7350..00000000000 --- a/idea/testData/quickfix/asyncUnsupported/asyncWithTimes.kt.after +++ /dev/null @@ -1,8 +0,0 @@ -// "Migrate unsupported async syntax" "true" -object async { - operator fun times(f: () -> Unit) = f() -} - -fun test() { - async * { } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 050805c3b87..f0910b1e702 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -615,12 +615,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncWithLambdaAndComment.kt"); doTest(fileName); } - - @TestMetadata("asyncWithTimes.kt") - public void testAsyncWithTimes() throws Exception { - String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/asyncUnsupported/asyncWithTimes.kt"); - doTest(fileName); - } } @TestMetadata("idea/testData/quickfix/autoImports")