From 7c2825b397da50d3498f1a33e542a7bdc6c30062 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Wed, 22 Jun 2016 21:25:55 +0300 Subject: [PATCH] KT-12623 Fixed ISE: Type parameter ... not found for public fun ... #KT-12623 Fixed Also EA-72653 fixed. --- .../kotlin/parsing/KotlinParsing.java | 13 ++++- compiler/testData/psi/Functions_ERR.kt | 6 +- compiler/testData/psi/Functions_ERR.txt | 57 +++++++++++++++++++ .../inspectionData/expected.xml | 1 + .../inspectionData/inspections.test | 1 + .../twoSetOfTypeparameters/test.kt | 5 ++ .../codeInsight/InspectionTestGenerated.java | 6 ++ 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 idea/testData/inspections/twoSetOfTypeparameters/inspectionData/expected.xml create mode 100644 idea/testData/inspections/twoSetOfTypeparameters/inspectionData/inspections.test create mode 100644 idea/testData/inspections/twoSetOfTypeparameters/test.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java index a910a6c95ff..79af3435c21 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1486,7 +1486,16 @@ public class KotlinParsing extends AbstractKotlinParsing { if (at(LT)) { PsiBuilder.Marker error = mark(); parseTypeParameterList(TokenSet.orSet(TokenSet.create(LPAR), valueParametersFollow)); - errorIf(error, typeParameterListOccurred, "Only one type parameter list is allowed for a function"); + if (typeParameterListOccurred) { + int offset = myBuilder.getCurrentOffset(); + error.rollbackTo(); + error = mark(); + advance(offset - myBuilder.getCurrentOffset()); + error.error("Only one type parameter list is allowed for a function"); + } + else { + error.drop(); + } typeParameterListOccurred = true; } diff --git a/compiler/testData/psi/Functions_ERR.kt b/compiler/testData/psi/Functions_ERR.kt index 21ba7455331..64f3779b6ef 100644 --- a/compiler/testData/psi/Functions_ERR.kt +++ b/compiler/testData/psi/Functions_ERR.kt @@ -6,4 +6,8 @@ fun @[a()] T.foo<, T, , T>(a : foo) : bar fun @[a()] T.foo(, a : foo, , a: b) : bar fun foo() : = a; -fun foo() = ; \ No newline at end of file +fun foo() = ; + +fun foo() +fun foo A. PsiWhiteSpace(' ') PsiElement(SEMICOLON)(';') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiErrorElement:Only one type parameter list is allowed for a function + PsiElement(LT)('<') + PsiElement(IDENTIFIER)('D') + PsiElement(GT)('>') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + PsiErrorElement:Only one type parameter list is allowed for a function + PsiElement(LT)('<') + PsiElement(IDENTIFIER)('D') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + PsiElement(DOT)('.') + PsiErrorElement:Only one type parameter list is allowed for a function + PsiElement(LT)('<') + PsiElement(IDENTIFIER)('foo') + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiErrorElement:Expecting '(' + \ No newline at end of file diff --git a/idea/testData/inspections/twoSetOfTypeparameters/inspectionData/expected.xml b/idea/testData/inspections/twoSetOfTypeparameters/inspectionData/expected.xml new file mode 100644 index 00000000000..9f597d78663 --- /dev/null +++ b/idea/testData/inspections/twoSetOfTypeparameters/inspectionData/expected.xml @@ -0,0 +1 @@ + diff --git a/idea/testData/inspections/twoSetOfTypeparameters/inspectionData/inspections.test b/idea/testData/inspections/twoSetOfTypeparameters/inspectionData/inspections.test new file mode 100644 index 00000000000..cd9b3e9457f --- /dev/null +++ b/idea/testData/inspections/twoSetOfTypeparameters/inspectionData/inspections.test @@ -0,0 +1 @@ +// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.OverridingDeprecatedMemberInspection \ No newline at end of file diff --git a/idea/testData/inspections/twoSetOfTypeparameters/test.kt b/idea/testData/inspections/twoSetOfTypeparameters/test.kt new file mode 100644 index 00000000000..6614590a701 --- /dev/null +++ b/idea/testData/inspections/twoSetOfTypeparameters/test.kt @@ -0,0 +1,5 @@ +// KT-12623 ISE: Type parameter ... not found for public fun ... + +fun boo() {} + +fun > Collection Boolean): Pair = TODO() \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java index ae1625946b3..5d5fde68b67 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java @@ -214,6 +214,12 @@ public class InspectionTestGenerated extends AbstractInspectionTest { doTest(fileName); } + @TestMetadata("twoSetOfTypeparameters/inspectionData/inspections.test") + public void testTwoSetOfTypeparameters_inspectionData_Inspections_test() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspections/twoSetOfTypeparameters/inspectionData/inspections.test"); + doTest(fileName); + } + @TestMetadata("unusedImport/inspectionData/inspections.test") public void testUnusedImport_inspectionData_Inspections_test() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspections/unusedImport/inspectionData/inspections.test");