Report warning on characters which can cause problems on Windows
As soon as we fix KT-17438, this warning will be turned into an error.
This commit is contained in:
+5
@@ -5616,6 +5616,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt");
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameWithDangerousCharacters.kt")
|
||||||
|
public void testNameWithDangerousCharacters() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/nameWithDangerousCharacters.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("namedFunAsLastExpressionInBlock.kt")
|
@TestMetadata("namedFunAsLastExpressionInBlock.kt")
|
||||||
public void testNamedFunAsLastExpressionInBlock() throws Exception {
|
public void testNamedFunAsLastExpressionInBlock() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt");
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt");
|
||||||
|
|||||||
+20
-8
@@ -21,11 +21,15 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
|||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.IdentifierChecker
|
import org.jetbrains.kotlin.resolve.IdentifierChecker
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
|
|
||||||
object JvmSimpleNameBacktickChecker : IdentifierChecker {
|
object JvmSimpleNameBacktickChecker : IdentifierChecker {
|
||||||
// See The Java Virtual Machine Specification, section 4.7.9.1 https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.9.1
|
// See The Java Virtual Machine Specification, section 4.7.9.1 https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.9.1
|
||||||
val INVALID_CHARS = setOf('.', ';', '[', ']', '/', '<', '>', ':', '\\')
|
val INVALID_CHARS = setOf('.', ';', '[', ']', '/', '<', '>', ':', '\\')
|
||||||
|
|
||||||
|
// These characters can cause problems on Windows. '?*"|' are not allowed in file names, and % leads to unexpected env var expansion.
|
||||||
|
private val DANGEROUS_CHARS = setOf('?', '*', '"', '|', '%')
|
||||||
|
|
||||||
override fun checkIdentifier(simpleNameExpression: KtSimpleNameExpression, diagnosticHolder: DiagnosticSink) {
|
override fun checkIdentifier(simpleNameExpression: KtSimpleNameExpression, diagnosticHolder: DiagnosticSink) {
|
||||||
reportIfNeeded(simpleNameExpression.getReferencedName(), { simpleNameExpression.getIdentifier() }, diagnosticHolder)
|
reportIfNeeded(simpleNameExpression.getReferencedName(), { simpleNameExpression.getIdentifier() }, diagnosticHolder)
|
||||||
}
|
}
|
||||||
@@ -53,15 +57,23 @@ object JvmSimpleNameBacktickChecker : IdentifierChecker {
|
|||||||
|
|
||||||
private fun reportIfNeeded(name: String, reportOn: () -> PsiElement?, diagnosticHolder: DiagnosticSink) {
|
private fun reportIfNeeded(name: String, reportOn: () -> PsiElement?, diagnosticHolder: DiagnosticSink) {
|
||||||
val text = KtPsiUtil.unquoteIdentifier(name)
|
val text = KtPsiUtil.unquoteIdentifier(name)
|
||||||
if (text.isEmpty()) {
|
when {
|
||||||
diagnosticHolder.report(Errors.INVALID_CHARACTERS.on(reportOn() ?: return, "should not be empty"))
|
text.isEmpty() -> {
|
||||||
} else if (text.any { it in INVALID_CHARS }) {
|
diagnosticHolder.report(Errors.INVALID_CHARACTERS.on(reportOn() ?: return, "should not be empty"))
|
||||||
diagnosticHolder.report(
|
}
|
||||||
Errors.INVALID_CHARACTERS.on(
|
text.any { it in INVALID_CHARS } -> {
|
||||||
reportOn() ?: return,
|
diagnosticHolder.report(
|
||||||
"contains illegal characters: ${INVALID_CHARS.intersect(text.toSet()).joinToString("")}"
|
Errors.INVALID_CHARACTERS.on(
|
||||||
|
reportOn() ?: return,
|
||||||
|
"contains illegal characters: ${INVALID_CHARS.intersect(text.toSet()).joinToString("")}"
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
|
text.any { it in DANGEROUS_CHARS } -> {
|
||||||
|
diagnosticHolder.report(
|
||||||
|
ErrorsJvm.DANGEROUS_CHARACTERS.on(reportOn() ?: return, DANGEROUS_CHARS.intersect(text.toSet()).joinToString(""))
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -165,6 +165,8 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
|||||||
"or annotate the class with @JvmDefaultWithoutCompatibility. " +
|
"or annotate the class with @JvmDefaultWithoutCompatibility. " +
|
||||||
"Please refer to KT-39603 for details",
|
"Please refer to KT-39603 for details",
|
||||||
COMPACT, SHORT_NAMES_IN_TYPES);
|
COMPACT, SHORT_NAMES_IN_TYPES);
|
||||||
|
|
||||||
|
MAP.put(DANGEROUS_CHARACTERS, "Name contains characters which can cause problems on Windows: {0}", STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -141,6 +141,8 @@ public interface ErrorsJvm {
|
|||||||
|
|
||||||
DiagnosticFactory2<KtDeclaration, CallableDescriptor, CallableDescriptor> EXPLICIT_OVERRIDE_REQUIRED_IN_COMPATIBILITY_MODE = DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
DiagnosticFactory2<KtDeclaration, CallableDescriptor, CallableDescriptor> EXPLICIT_OVERRIDE_REQUIRED_IN_COMPATIBILITY_MODE = DiagnosticFactory2.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||||
|
|
||||||
|
DiagnosticFactory1<PsiElement, String> DANGEROUS_CHARACTERS = DiagnosticFactory1.create(WARNING);
|
||||||
|
|
||||||
@SuppressWarnings("UnusedDeclaration")
|
@SuppressWarnings("UnusedDeclaration")
|
||||||
Object _initializer = new Object() {
|
Object _initializer = new Object() {
|
||||||
{
|
{
|
||||||
|
|||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
class `A?B`
|
||||||
|
class `A*B`
|
||||||
|
class `A"B`
|
||||||
|
class `A|B`
|
||||||
|
class `A%B`
|
||||||
|
|
||||||
|
fun `?*"|%`(): Int {
|
||||||
|
val `?` = 0
|
||||||
|
return `?`
|
||||||
|
}
|
||||||
|
|
||||||
|
val `"a"+"b"` = "c"
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
class <!DANGEROUS_CHARACTERS!>`A?B`<!>
|
||||||
|
class <!DANGEROUS_CHARACTERS!>`A*B`<!>
|
||||||
|
class <!DANGEROUS_CHARACTERS!>`A"B`<!>
|
||||||
|
class <!DANGEROUS_CHARACTERS!>`A|B`<!>
|
||||||
|
class <!DANGEROUS_CHARACTERS!>`A%B`<!>
|
||||||
|
|
||||||
|
fun <!DANGEROUS_CHARACTERS!>`?*"|%`<!>(): Int {
|
||||||
|
val <!DANGEROUS_CHARACTERS!>`?`<!> = 0
|
||||||
|
return `?`
|
||||||
|
}
|
||||||
|
|
||||||
|
val <!DANGEROUS_CHARACTERS!>`"a"+"b"`<!> = "c"
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val `"a"+"b"`: kotlin.String = "c"
|
||||||
|
public fun `?*"|%`(): kotlin.Int
|
||||||
|
|
||||||
|
public final class `A"B` {
|
||||||
|
public constructor `A"B`()
|
||||||
|
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class `A%B` {
|
||||||
|
public constructor `A%B`()
|
||||||
|
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class `A*B` {
|
||||||
|
public constructor `A*B`()
|
||||||
|
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class `A?B` {
|
||||||
|
public constructor `A?B`()
|
||||||
|
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class `A|B` {
|
||||||
|
public constructor `A|B`()
|
||||||
|
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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -5623,6 +5623,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
|||||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt");
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameWithDangerousCharacters.kt")
|
||||||
|
public void testNameWithDangerousCharacters() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/nameWithDangerousCharacters.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("namedFunAsLastExpressionInBlock.kt")
|
@TestMetadata("namedFunAsLastExpressionInBlock.kt")
|
||||||
public void testNamedFunAsLastExpressionInBlock() throws Exception {
|
public void testNamedFunAsLastExpressionInBlock() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt");
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt");
|
||||||
|
|||||||
Generated
+5
@@ -5618,6 +5618,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt");
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/MultiDeclarationErrors.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nameWithDangerousCharacters.kt")
|
||||||
|
public void testNameWithDangerousCharacters() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/nameWithDangerousCharacters.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("namedFunAsLastExpressionInBlock.kt")
|
@TestMetadata("namedFunAsLastExpressionInBlock.kt")
|
||||||
public void testNamedFunAsLastExpressionInBlock() throws Exception {
|
public void testNamedFunAsLastExpressionInBlock() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt");
|
runTest("compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user