001 /* 002 * Copyright 2010-2015 JetBrains s.r.o. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.jetbrains.kotlin.diagnostics.rendering; 018 019 import com.intellij.openapi.extensions.ExtensionPointName; 020 import kotlin.Unit; 021 import kotlin.jvm.functions.Function1; 022 import org.jetbrains.annotations.NotNull; 023 import org.jetbrains.annotations.Nullable; 024 import org.jetbrains.annotations.TestOnly; 025 import org.jetbrains.kotlin.diagnostics.Diagnostic; 026 import org.jetbrains.kotlin.diagnostics.DiagnosticFactory; 027 import org.jetbrains.kotlin.diagnostics.Errors; 028 import org.jetbrains.kotlin.diagnostics.TypeMismatchDueToTypeProjectionsData; 029 import org.jetbrains.kotlin.psi.KtExpression; 030 import org.jetbrains.kotlin.psi.KtSimpleNameExpression; 031 import org.jetbrains.kotlin.psi.KtTypeConstraint; 032 import org.jetbrains.kotlin.renderer.DescriptorRenderer; 033 import org.jetbrains.kotlin.renderer.DescriptorRendererOptions; 034 import org.jetbrains.kotlin.renderer.MultiRenderer; 035 import org.jetbrains.kotlin.renderer.Renderer; 036 import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker.VarianceConflictDiagnosticData; 037 import org.jetbrains.kotlin.types.KotlinType; 038 import org.jetbrains.kotlin.util.MappedExtensionProvider; 039 import org.jetbrains.kotlin.util.OperatorNameConventions; 040 041 import java.lang.reflect.Field; 042 import java.lang.reflect.Modifier; 043 import java.util.ArrayList; 044 import java.util.List; 045 046 import static org.jetbrains.kotlin.diagnostics.Errors.*; 047 import static org.jetbrains.kotlin.diagnostics.rendering.Renderers.*; 048 import static org.jetbrains.kotlin.renderer.DescriptorRenderer.*; 049 050 public class DefaultErrorMessages { 051 052 public interface Extension { 053 ExtensionPointName<Extension> EP_NAME = ExtensionPointName.create("org.jetbrains.kotlin.defaultErrorMessages"); 054 055 @NotNull 056 DiagnosticFactoryToRendererMap getMap(); 057 } 058 059 private static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap("Default"); 060 private static final MappedExtensionProvider<Extension, List<DiagnosticFactoryToRendererMap>> RENDERER_MAPS = MappedExtensionProvider.create( 061 Extension.EP_NAME, 062 new Function1<List<? extends Extension>, List<DiagnosticFactoryToRendererMap>>() { 063 @Override 064 public List<DiagnosticFactoryToRendererMap> invoke(List<? extends Extension> extensions) { 065 List<DiagnosticFactoryToRendererMap> result = new ArrayList<DiagnosticFactoryToRendererMap>(extensions.size() + 1); 066 for (Extension extension : extensions) { 067 result.add(extension.getMap()); 068 } 069 result.add(MAP); 070 return result; 071 } 072 }); 073 074 @NotNull 075 public static String render(@NotNull Diagnostic diagnostic) { 076 for (DiagnosticFactoryToRendererMap map : RENDERER_MAPS.get()) { 077 DiagnosticRenderer renderer = map.get(diagnostic.getFactory()); 078 if (renderer != null) { 079 //noinspection unchecked 080 return renderer.render(diagnostic); 081 } 082 } 083 throw new IllegalArgumentException("Don't know how to render diagnostic of type " + diagnostic.getFactory().getName() + 084 " with the following renderer maps: " + RENDERER_MAPS.get()); 085 } 086 087 @TestOnly 088 @Nullable 089 public static DiagnosticRenderer getRendererForDiagnostic(@NotNull Diagnostic diagnostic) { 090 for (DiagnosticFactoryToRendererMap map : RENDERER_MAPS.get()) { 091 DiagnosticRenderer renderer = map.get(diagnostic.getFactory()); 092 093 if (renderer != null) return renderer; 094 } 095 096 return null; 097 } 098 099 public static final DescriptorRenderer DEPRECATION_RENDERER = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.withOptions( 100 new Function1<DescriptorRendererOptions, Unit>() { 101 @Override 102 public Unit invoke(DescriptorRendererOptions options) { 103 options.setWithoutTypeParameters(false); 104 options.setReceiverAfterName(false); 105 options.setRenderAccessors(true); 106 return Unit.INSTANCE; 107 } 108 } 109 ); 110 111 static { 112 MAP.put(UNRESOLVED_REFERENCE, "Unresolved reference: {0}", ELEMENT_TEXT); 113 114 MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is ''{1}'' in {2}", NAME, TO_STRING, NAME_OF_PARENT_OR_FILE); 115 MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is ''{1}'' in {2}", NAME, TO_STRING, NAME_OF_PARENT_OR_FILE); 116 117 MAP.put(EXPOSED_PROPERTY_TYPE, "Property effective visibility ''{0}'' should be the same or less permissive than its type effective visibility ''{1}''", TO_STRING, TO_STRING); 118 MAP.put(EXPOSED_FUNCTION_RETURN_TYPE, "Function effective visibility ''{0}'' should be the same or less permissive than its return type effective visibility ''{1}''", TO_STRING, TO_STRING); 119 MAP.put(EXPOSED_PARAMETER_TYPE, "Function effective visibility ''{0}'' should be the same or less permissive than its parameter type effective visibility ''{1}''", TO_STRING, TO_STRING); 120 MAP.put(EXPOSED_RECEIVER_TYPE, "Member effective visibility ''{0}'' should be the same or less permissive than its receiver type effective visibility ''{1}''", TO_STRING, TO_STRING); 121 MAP.put(EXPOSED_TYPE_PARAMETER_BOUND, "Generic effective visibility ''{0}'' should be the same or less permissive than its type parameter bound effective visibility ''{1}''", TO_STRING, TO_STRING); 122 MAP.put(EXPOSED_SUPER_CLASS, "Subclass effective visibility ''{0}'' should be the same or less permissive than its superclass effective visibility ''{1}''", TO_STRING, TO_STRING); 123 MAP.put(EXPOSED_SUPER_INTERFACE, "Sub-interface effective visibility ''{0}'' should be the same or less permissive than its super-interface effective visibility ''{1}''", TO_STRING, TO_STRING); 124 125 MAP.put(REDECLARATION, "Redeclaration: {0}", STRING); 126 MAP.put(NAME_SHADOWING, "Name shadowed: {0}", STRING); 127 MAP.put(ACCESSOR_PARAMETER_NAME_SHADOWING, "Accessor parameter name 'field' is shadowed by backing field variable"); 128 129 MAP.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE); 130 MAP.put(TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS, 131 "Type mismatch: inferred type is {1} but {0} was expected. Projected type {2} restricts use of {3}", 132 new MultiRenderer<TypeMismatchDueToTypeProjectionsData>() { 133 @NotNull 134 @Override 135 public String[] render(@NotNull TypeMismatchDueToTypeProjectionsData object) { 136 return new String[] { 137 RENDER_TYPE.render(object.getExpectedType()), 138 RENDER_TYPE.render(object.getExpressionType()), 139 RENDER_TYPE.render(object.getReceiverType()), 140 DescriptorRenderer.FQ_NAMES_IN_TYPES.render(object.getCallableDescriptor()) 141 }; 142 } 143 }); 144 145 MAP.put(MEMBER_PROJECTED_OUT, "Out-projected type ''{1}'' prohibits the use of ''{0}''", DescriptorRenderer.FQ_NAMES_IN_TYPES, RENDER_TYPE); 146 MAP.put(INCOMPATIBLE_MODIFIERS, "Modifier ''{0}'' is incompatible with ''{1}''", TO_STRING, TO_STRING); 147 MAP.put(DEPRECATED_MODIFIER_PAIR, "Modifier ''{0}'' is deprecated in presence of ''{1}''", TO_STRING, TO_STRING); 148 MAP.put(REPEATED_MODIFIER, "Repeated ''{0}''", TO_STRING); 149 MAP.put(WRONG_MODIFIER_TARGET, "Modifier ''{0}'' is not applicable to ''{1}''", TO_STRING, TO_STRING); 150 MAP.put(DEPRECATED_MODIFIER_FOR_TARGET, "Modifier ''{0}'' is deprecated for ''{1}''", TO_STRING, TO_STRING); 151 MAP.put(REDUNDANT_MODIFIER_FOR_TARGET, "Modifier ''{0}'' is redundant for ''{1}''", TO_STRING, TO_STRING); 152 MAP.put(WRONG_MODIFIER_CONTAINING_DECLARATION, "Modifier ''{0}'' is not applicable inside ''{1}''", TO_STRING, TO_STRING); 153 MAP.put(DEPRECATED_MODIFIER_CONTAINING_DECLARATION, "Modifier ''{0}'' is deprecated inside ''{1}''", TO_STRING, TO_STRING); 154 MAP.put(ILLEGAL_INLINE_PARAMETER_MODIFIER, "Modifier ''{0}'' is allowed only for function parameters of an inline function", TO_STRING); 155 MAP.put(WRONG_ANNOTATION_TARGET, "This annotation is not applicable to target ''{0}''", TO_STRING); 156 MAP.put(WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET, "This annotation is not applicable to target ''{0}'' and use site target ''@{1}''", TO_STRING, TO_STRING); 157 MAP.put(REPEATED_ANNOTATION, "This annotation is not repeatable"); 158 MAP.put(NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION, "The lambda expression here is an inlined argument so this annotation cannot be stored anywhere"); 159 160 MAP.put(INAPPLICABLE_TARGET_ON_PROPERTY, "''@{0}:'' annotations could be applied only to property declarations", TO_STRING); 161 MAP.put(INAPPLICABLE_TARGET_PROPERTY_IMMUTABLE, "''@{0}:'' annotations could be applied only to mutable properties", TO_STRING); 162 MAP.put(INAPPLICABLE_TARGET_PROPERTY_HAS_NO_DELEGATE, "''@delegate:'' annotations could be applied only to delegated properties"); 163 MAP.put(INAPPLICABLE_TARGET_PROPERTY_HAS_NO_BACKING_FIELD, "''@field:'' annotations could be applied only to properties with backing fields"); 164 MAP.put(INAPPLICABLE_RECEIVER_TARGET, "''@receiver:'' annotations could be applied only to extension function or extension property declarations"); 165 MAP.put(INAPPLICABLE_PARAM_TARGET, "''@param:'' annotations could be applied only to primary constructor parameters"); 166 MAP.put(REDUNDANT_ANNOTATION_TARGET, "Redundant annotation target ''{0}''", STRING); 167 168 MAP.put(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING); 169 MAP.put(ABSTRACT_MODIFIER_IN_INTERFACE, "Modifier ''abstract'' is redundant in interface"); 170 MAP.put(REDUNDANT_MODIFIER_IN_GETTER, "Visibility modifiers are redundant in getter"); 171 MAP.put(TYPE_PARAMETERS_IN_ENUM, "Enum class cannot have type parameters"); 172 MAP.put(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, 173 "Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly"); // TODO: message 174 MAP.put(RETURN_NOT_ALLOWED, "'return' is not allowed here"); 175 MAP.put(PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE, "Projections are not allowed for immediate arguments of a supertype"); 176 MAP.put(LABEL_NAME_CLASH, "There is more than one label with such a name in this scope"); 177 MAP.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, "Expression expected, but a package name found"); 178 179 MAP.put(CANNOT_ALL_UNDER_IMPORT_FROM_SINGLETON, "Cannot import-on-demand from object ''{0}''", NAME); 180 MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages or objects", TO_STRING); 181 MAP.put(PACKAGE_CANNOT_BE_IMPORTED, "Packages cannot be imported"); 182 MAP.put(CONFLICTING_IMPORT, "Conflicting import, imported name ''{0}'' is ambiguous", STRING); 183 MAP.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class shouldn''t be used in Kotlin. Use {0} instead.", CLASSES_OR_SEPARATED); 184 185 MAP.put(CANNOT_INFER_PARAMETER_TYPE, "Cannot infer a type for this parameter. Please specify it explicitly."); 186 187 MAP.put(MIXING_NAMED_AND_POSITIONED_ARGUMENTS, "Mixing named and positioned arguments is not allowed"); 188 MAP.put(ARGUMENT_PASSED_TWICE, "An argument is already passed for this parameter"); 189 MAP.put(NAMED_PARAMETER_NOT_FOUND, "Cannot find a parameter with this name: {0}", ELEMENT_TEXT); 190 MAP.put(NAMED_ARGUMENTS_NOT_ALLOWED, "Named arguments are not allowed for {0}", new Renderer<BadNamedArgumentsTarget>() { 191 @NotNull 192 @Override 193 public String render(@NotNull BadNamedArgumentsTarget target) { 194 switch (target) { 195 case NON_KOTLIN_FUNCTION: 196 return "non-Kotlin functions"; 197 case INVOKE_ON_FUNCTION_TYPE: 198 return "function types"; 199 default: 200 throw new AssertionError(target); 201 } 202 } 203 }); 204 205 MAP.put(VARARG_OUTSIDE_PARENTHESES, "Passing value as a vararg is only allowed inside a parenthesized argument list"); 206 MAP.put(NON_VARARG_SPREAD, "The spread operator (*foo) may only be applied in a vararg position"); 207 MAP.put(SPREAD_OF_NULLABLE, "The spread operator (*foo) may not be applied to an argument of nullable type"); 208 209 MAP.put(MANY_LAMBDA_EXPRESSION_ARGUMENTS, "Only one lambda expression is allowed outside a parenthesized argument list"); 210 MAP.put(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER, "This property must either have a type annotation, be initialized or be delegated"); 211 MAP.put(VARIABLE_WITH_NO_TYPE_NO_INITIALIZER, "This variable must either have a type annotation or be initialized"); 212 213 MAP.put(INITIALIZER_REQUIRED_FOR_DESTRUCTURING_DECLARATION, "Initializer required for destructuring declaration"); 214 MAP.put(COMPONENT_FUNCTION_MISSING, "Destructuring declaration initializer of type {1} must have a ''{0}()'' function", TO_STRING, RENDER_TYPE); 215 MAP.put(COMPONENT_FUNCTION_AMBIGUITY, "Function ''{0}()'' is ambiguous for this expression: {1}", TO_STRING, AMBIGUOUS_CALLS); 216 MAP.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, "''{0}()'' function returns ''{1}'', but ''{2}'' is expected", 217 TO_STRING, RENDER_TYPE, RENDER_TYPE); 218 219 MAP.put(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, "This property cannot be declared abstract"); 220 MAP.put(ABSTRACT_PROPERTY_WITH_INITIALIZER, "Property with initializer cannot be abstract"); 221 MAP.put(ABSTRACT_PROPERTY_WITH_GETTER, "Property with getter implementation cannot be abstract"); 222 MAP.put(ABSTRACT_PROPERTY_WITH_SETTER, "Property with setter implementation cannot be abstract"); 223 224 MAP.put(ABSTRACT_DELEGATED_PROPERTY, "Delegated property cannot be abstract"); 225 MAP.put(ACCESSOR_FOR_DELEGATED_PROPERTY, "Delegated property cannot have accessors with non-default implementations"); 226 MAP.put(DELEGATED_PROPERTY_IN_INTERFACE, "Delegated properties are not allowed in interfaces"); 227 MAP.put(LOCAL_VARIABLE_WITH_DELEGATE, "Local variables are not allowed to have delegates"); 228 229 MAP.put(INAPPLICABLE_LATEINIT_MODIFIER, "''lateinit'' modifier {0}", STRING); 230 231 MAP.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, "Getter visibility must be the same as property visibility"); 232 MAP.put(SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY, "Setter visibility must be the same or less permissive than property visibility"); 233 MAP.put(PRIVATE_SETTER_FOR_ABSTRACT_PROPERTY, "Private setters are not allowed for abstract properties"); 234 MAP.put(PRIVATE_SETTER_FOR_OPEN_PROPERTY, "Private setters are not allowed for open properties"); 235 MAP.put(BACKING_FIELD_IN_INTERFACE, "Property in an interface cannot have a backing field"); 236 MAP.put(MUST_BE_INITIALIZED, "Property must be initialized"); 237 MAP.put(MUST_BE_INITIALIZED_OR_BE_ABSTRACT, "Property must be initialized or be abstract"); 238 MAP.put(PROPERTY_INITIALIZER_IN_INTERFACE, "Property initializers are not allowed in interfaces"); 239 MAP.put(PRIVATE_PROPERTY_IN_INTERFACE, "Abstract property in an interface cannot be private"); 240 MAP.put(EXTENSION_PROPERTY_WITH_BACKING_FIELD, "Extension property cannot be initialized because it has no backing field"); 241 MAP.put(PROPERTY_INITIALIZER_NO_BACKING_FIELD, "Initializer is not allowed here because this property has no backing field"); 242 MAP.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, "Abstract property ''{0}'' in non-abstract class ''{1}''", STRING, NAME); 243 MAP.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, "Abstract function ''{0}'' in non-abstract class ''{1}''", STRING, NAME); 244 MAP.put(ABSTRACT_FUNCTION_WITH_BODY, "A function ''{0}'' with body cannot be abstract", NAME); 245 MAP.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without a body must be abstract", NAME); 246 MAP.put(PRIVATE_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without body cannot be private", NAME); 247 248 MAP.put(NON_MEMBER_FUNCTION_NO_BODY, "Function ''{0}'' must have a body", NAME); 249 MAP.put(FUNCTION_DECLARATION_WITH_NO_NAME, "Function declaration must have a name"); 250 MAP.put(ANONYMOUS_FUNCTION_WITH_NAME, "Anonymous functions with names are prohibited"); 251 MAP.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, "\"open\" has no effect in a final class"); 252 MAP.put(NON_FINAL_MEMBER_IN_OBJECT, "\"open\" has no effect in an object"); 253 254 MAP.put(ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE, "An anonymous function is not allowed to specify default values for its parameters"); 255 MAP.put(USELESS_VARARG_ON_PARAMETER, "Vararg on this parameter is useless"); 256 MAP.put(MULTIPLE_VARARG_PARAMETERS, "Multiple vararg-parameters are prohibited"); 257 258 MAP.put(PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT, "Projections are not allowed on type arguments of functions and properties"); 259 MAP.put(SUPERTYPE_NOT_INITIALIZED, "This type has a constructor, and thus must be initialized here"); 260 MAP.put(NOTHING_TO_OVERRIDE, "''{0}'' overrides nothing", NAME); 261 MAP.put(VIRTUAL_MEMBER_HIDDEN, "''{0}'' hides member of supertype ''{2}'' and needs ''override'' modifier", NAME, NAME, NAME); 262 263 MAP.put(DATA_CLASS_OVERRIDE_CONFLICT, "Function ''{0}'' generated for the data class conflicts with member of supertype ''{1}''", NAME, NAME); 264 265 MAP.put(CANNOT_OVERRIDE_INVISIBLE_MEMBER, "''{0}'' has no access to ''{1}'', so it cannot override it", FQ_NAMES_IN_TYPES, 266 FQ_NAMES_IN_TYPES); 267 MAP.put(CANNOT_INFER_VISIBILITY, "Cannot infer visibility for ''{0}''. Please specify it explicitly", COMPACT); 268 269 MAP.put(ENUM_ENTRY_SHOULD_BE_INITIALIZED, "Enum has no default constructor, use 'entry(parameters)'"); 270 271 MAP.put(UNINITIALIZED_VARIABLE, "Variable ''{0}'' must be initialized", NAME); 272 MAP.put(UNINITIALIZED_PARAMETER, "Parameter ''{0}'' is uninitialized here", NAME); 273 MAP.put(UNUSED_VARIABLE, "Variable ''{0}'' is never used", NAME); 274 MAP.put(UNUSED_PARAMETER, "Parameter ''{0}'' is never used", NAME); 275 MAP.put(ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE, "Variable ''{0}'' is assigned but never accessed", NAME); 276 MAP.put(VARIABLE_WITH_REDUNDANT_INITIALIZER, "Variable ''{0}'' initializer is redundant", NAME); 277 MAP.put(UNUSED_VALUE, "The value ''{0}'' assigned to ''{1}'' is never used", ELEMENT_TEXT, FQ_NAMES_IN_TYPES); 278 MAP.put(UNUSED_CHANGED_VALUE, "The value changed at ''{0}'' is never used", ELEMENT_TEXT); 279 MAP.put(UNUSED_EXPRESSION, "The expression is unused"); 280 MAP.put(UNUSED_LAMBDA_EXPRESSION, "The lambda expression is unused. If you mean a block, you can use 'run { ... }'"); 281 282 MAP.put(VAL_REASSIGNMENT, "Val cannot be reassigned", NAME); 283 MAP.put(SETTER_PROJECTED_OUT, "Setter for ''{0}'' is removed by type projection", NAME); 284 MAP.put(INVISIBLE_SETTER, "Cannot assign to ''{0}'': the setter is ''{1}'' in {2}", NAME, TO_STRING, NAME_OF_PARENT_OR_FILE); 285 MAP.put(INITIALIZATION_BEFORE_DECLARATION, "Variable cannot be initialized before declaration", NAME); 286 MAP.put(VARIABLE_EXPECTED, "Variable expected"); 287 288 MAP.put(VAL_OR_VAR_ON_LOOP_PARAMETER, "''{0}'' on loop parameter is not allowed", TO_STRING); 289 MAP.put(VAL_OR_VAR_ON_LOOP_MULTI_PARAMETER, "''{0}'' on loop multi parameter is not allowed", TO_STRING); 290 MAP.put(VAL_OR_VAR_ON_FUN_PARAMETER, "''{0}'' on function parameter is not allowed", TO_STRING); 291 MAP.put(VAL_OR_VAR_ON_CATCH_PARAMETER, "''{0}'' on catch parameter is not allowed", TO_STRING); 292 MAP.put(VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER, "''{0}'' on secondary constructor parameter is not allowed", TO_STRING); 293 294 MAP.put(UNREACHABLE_CODE, "Unreachable code", TO_STRING); 295 296 MAP.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class"); 297 298 MAP.put(DEPRECATION, "''{0}'' is deprecated. {1}", DEPRECATION_RENDERER, STRING); 299 MAP.put(DEPRECATION_ERROR, "Using ''{0}'' is an error. {1}", DEPRECATION_RENDERER, STRING); 300 301 MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME); 302 MAP.put(LOCAL_INTERFACE_NOT_ALLOWED, "''{0}'' is an interface so it cannot be local. Try to use anonymous object or abstract class instead", NAME); 303 MAP.put(ENUM_CLASS_CONSTRUCTOR_CALL, "Enum types cannot be instantiated"); 304 MAP.put(SEALED_CLASS_CONSTRUCTOR_CALL, "Sealed types cannot be instantiated"); 305 306 MAP.put(DELEGATION_IN_INTERFACE, "Interfaces cannot use delegation"); 307 MAP.put(DELEGATION_NOT_TO_INTERFACE, "Only interfaces can be delegated to"); 308 MAP.put(NO_CONSTRUCTOR, "This class does not have a constructor"); 309 MAP.put(NOT_A_CLASS, "Not a class"); 310 MAP.put(ILLEGAL_ESCAPE_SEQUENCE, "Illegal escape sequence"); 311 312 MAP.put(LOCAL_EXTENSION_PROPERTY, "Local extension properties are not allowed"); 313 MAP.put(LOCAL_VARIABLE_WITH_GETTER, "Local variables are not allowed to have getters"); 314 MAP.put(LOCAL_VARIABLE_WITH_SETTER, "Local variables are not allowed to have setters"); 315 MAP.put(VAL_WITH_SETTER, "A 'val'-property cannot have a setter"); 316 317 MAP.put(NO_GET_METHOD, "No get method providing array access"); 318 MAP.put(NO_SET_METHOD, "No set method providing array access"); 319 320 MAP.put(DEPRECATED_UNARY_PLUS_MINUS, "Unary operation must be named ''{1}'', not ''{0}''", NAME, STRING); 321 322 MAP.put(INC_DEC_SHOULD_NOT_RETURN_UNIT, "Functions inc(), dec() shouldn't return Unit to be used by operators ++, --"); 323 MAP.put(ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT, "Function ''{0}'' should return Unit to be used by corresponding operator ''{1}''", 324 NAME, ELEMENT_TEXT); 325 MAP.put(ASSIGN_OPERATOR_AMBIGUITY, "Assignment operators ambiguity: {0}", AMBIGUOUS_CALLS); 326 327 MAP.put(EQUALS_MISSING, "No method 'equals(kotlin.Any?): kotlin.Boolean' available"); 328 MAP.put(ASSIGNMENT_IN_EXPRESSION_CONTEXT, "Assignments are not expressions, and only expressions are allowed in this context"); 329 MAP.put(SUPER_IS_NOT_AN_EXPRESSION, "''{0}'' is not an expression, it can only be used on the left-hand side of a dot ('.')", STRING); 330 MAP.put(SUPER_CANT_BE_EXTENSION_RECEIVER, "''{0}'' is not an expression, it can not be used as a receiver for extension functions", STRING); 331 MAP.put(DECLARATION_IN_ILLEGAL_CONTEXT, "Declarations are not allowed in this position"); 332 MAP.put(SETTER_PARAMETER_WITH_DEFAULT_VALUE, "Setter parameters cannot have default values"); 333 MAP.put(NO_THIS, "'this' is not defined in this context"); 334 MAP.put(SUPER_NOT_AVAILABLE, "No supertypes are accessible in this context"); 335 MAP.put(SUPERCLASS_NOT_ACCESSIBLE_FROM_INTERFACE, "Superclass is not accessible from interface"); 336 MAP.put(AMBIGUOUS_SUPER, "Many supertypes available, please specify the one you mean in angle brackets, e.g. 'super<Foo>'"); 337 MAP.put(ABSTRACT_SUPER_CALL, "Abstract member cannot be accessed directly"); 338 MAP.put(NOT_A_SUPERTYPE, "Not a supertype"); 339 MAP.put(TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, "Type arguments do not need to be specified in a 'super' qualifier"); 340 MAP.put(USELESS_CAST, "No cast needed"); 341 MAP.put(CAST_NEVER_SUCCEEDS, "This cast can never succeed"); 342 MAP.put(DYNAMIC_NOT_ALLOWED, "Dynamic types are not allowed in this position"); 343 MAP.put(IS_ENUM_ENTRY, "'is' over enum entry is not allowed, use comparison instead"); 344 MAP.put(ENUM_ENTRY_AS_TYPE, "Use of enum entry names as types is not allowed, use enum type instead"); 345 MAP.put(USELESS_NULLABLE_CHECK, "Non-null type is checked for instance of nullable type"); 346 MAP.put(WRONG_SETTER_PARAMETER_TYPE, "Setter parameter type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE); 347 MAP.put(WRONG_GETTER_RETURN_TYPE, "Getter return type must be equal to the type of the property, i.e. ''{0}''", RENDER_TYPE, RENDER_TYPE); 348 MAP.put(WRONG_SETTER_RETURN_TYPE, "Setter return type must be Unit"); 349 MAP.put(NO_COMPANION_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a companion object", NAME); 350 MAP.put(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION, "Type parameter ''{0}'' is not an expression", NAME); 351 MAP.put(TYPE_PARAMETER_ON_LHS_OF_DOT, "Type parameter ''{0}'' cannot have or inherit a companion object, so it cannot be on the left hand side of dot", NAME); 352 MAP.put(NO_GENERICS_IN_SUPERTYPE_SPECIFIER, "Generic arguments of the base type must be specified"); 353 MAP.put(NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE, "Nested {0} accessed via instance reference", RENDER_CLASS_OR_OBJECT_NAME); 354 MAP.put(NESTED_CLASS_SHOULD_BE_QUALIFIED, "Nested {0} should be qualified as ''{1}''", RENDER_CLASS_OR_OBJECT_NAME, TO_STRING); 355 356 MAP.put(INACCESSIBLE_OUTER_CLASS_EXPRESSION, "Expression is inaccessible from a nested class ''{0}'', use ''inner'' keyword to make the class inner", NAME); 357 MAP.put(NESTED_CLASS_NOT_ALLOWED, "Nested class is not allowed here, use ''inner'' keyword to make the class inner"); 358 359 MAP.put(HAS_NEXT_MISSING, "hasNext() cannot be called on iterator() of type ''{0}''", RENDER_TYPE); 360 MAP.put(HAS_NEXT_FUNCTION_AMBIGUITY, "hasNext() is ambiguous for iterator() of type ''{0}''", RENDER_TYPE); 361 MAP.put(HAS_NEXT_FUNCTION_NONE_APPLICABLE, "None of the hasNext() functions is applicable for iterator() of type ''{0}''", RENDER_TYPE); 362 MAP.put(HAS_NEXT_FUNCTION_TYPE_MISMATCH, "The ''iterator().hasNext()'' function of the loop range must return kotlin.Boolean, but returns {0}", RENDER_TYPE); 363 364 MAP.put(NEXT_MISSING, "next() cannot be called on iterator() of type ''{0}''", RENDER_TYPE); 365 MAP.put(NEXT_AMBIGUITY, "next() is ambiguous for iterator() of type ''{0}''", RENDER_TYPE); 366 MAP.put(NEXT_NONE_APPLICABLE, "None of the next() functions is applicable for iterator() of type ''{0}''", RENDER_TYPE); 367 368 MAP.put(ITERATOR_MISSING, "For-loop range must have an iterator() method"); 369 MAP.put(ITERATOR_AMBIGUITY, "Method ''iterator()'' is ambiguous for this expression: {0}", AMBIGUOUS_CALLS); 370 371 MAP.put(DELEGATE_SPECIAL_FUNCTION_MISSING, "Missing ''{0}'' method on delegate of type ''{1}''", STRING, RENDER_TYPE); 372 MAP.put(DELEGATE_RESOLVED_TO_DEPRECATED_CONVENTION, "''{0}'' method convention on type ''{1}'' is no longer supported. Rename to ''{2}''", NAME, RENDER_TYPE, STRING); 373 MAP.put(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, "Overload resolution ambiguity on method ''{0}'': {1}", STRING, AMBIGUOUS_CALLS); 374 MAP.put(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, "Property delegate must have a ''{0}'' method. None of the following functions is suitable: {1}", 375 STRING, AMBIGUOUS_CALLS); 376 MAP.put(DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH, "The ''{0}'' function of property delegate is expected to return ''{1}'', but returns ''{2}''", 377 STRING, RENDER_TYPE, RENDER_TYPE); 378 MAP.put(DELEGATE_PD_METHOD_NONE_APPLICABLE, "''{0}'' method may be missing. None of the following functions will be called: {1}", STRING, AMBIGUOUS_CALLS); 379 380 MAP.put(COMPARE_TO_TYPE_MISMATCH, "''compareTo()'' must return kotlin.Int, but returns {0}", RENDER_TYPE); 381 382 MAP.put(UNDERSCORE_IS_RESERVED, "Names _, __, ___, ..., are reserved in Kotlin"); 383 MAP.put(INVALID_CHARACTERS, "Name {0}", STRING); 384 385 MAP.put(INAPPLICABLE_OPERATOR_MODIFIER, "'operator' modifier is inapplicable on this function: {0}", STRING); 386 MAP.put(INAPPLICABLE_INFIX_MODIFIER, "'infix' modifier is inapplicable on this function"); 387 388 MAP.put(OPERATOR_MODIFIER_REQUIRED, "'operator' modifier is required on ''{0}'' in ''{1}''", NAME, STRING); 389 MAP.put(INFIX_MODIFIER_REQUIRED, "'infix' modifier is required on ''{0}'' in ''{1}''", NAME, STRING); 390 391 MAP.put(RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY, 392 "Returns are not allowed for functions with expression body. Use block body in '{...}'"); 393 MAP.put(NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY, "A 'return' expression required in a function with a block body ('{...}')"); 394 MAP.put(RETURN_TYPE_MISMATCH, "This function must return a value of type {0}", RENDER_TYPE); 395 MAP.put(EXPECTED_TYPE_MISMATCH, "Expected a value of type {0}", RENDER_TYPE); 396 MAP.put(ASSIGNMENT_TYPE_MISMATCH, 397 "Expected a value of type {0}. Assignment operation is not an expression, so it does not return any value", RENDER_TYPE); 398 399 MAP.put(EXPECTED_PARAMETER_TYPE_MISMATCH, "Expected parameter of type {0}", RENDER_TYPE); 400 MAP.put(EXPECTED_PARAMETERS_NUMBER_MISMATCH, "Expected {0,choice,0#no parameters|1#one parameter of type|1<{0,number,integer} parameters of types} {1}", null, RENDER_COLLECTION_OF_TYPES); 401 402 MAP.put(IMPLICIT_CAST_TO_ANY, "Conditional branch result of type {0} is implicitly cast to {1}", 403 RENDER_TYPE, RENDER_TYPE); 404 MAP.put(EXPRESSION_EXPECTED, "{0} is not an expression, and only expressions are allowed here", new Renderer<KtExpression>() { 405 @NotNull 406 @Override 407 public String render(@NotNull KtExpression expression) { 408 String expressionType = expression.toString(); 409 return expressionType.substring(0, 1) + 410 expressionType.substring(1).toLowerCase(); 411 } 412 }); 413 414 MAP.put(UPPER_BOUND_VIOLATED, "Type argument is not within its bounds: should be subtype of ''{0}''", RENDER_TYPE, RENDER_TYPE); 415 MAP.put(FINAL_UPPER_BOUND, "''{0}'' is a final type, and thus a value of the type parameter is predetermined", RENDER_TYPE); 416 MAP.put(UPPER_BOUND_IS_EXTENSION_FUNCTION_TYPE, "Extension function type can not be used as an upper bound"); 417 MAP.put(ONLY_ONE_CLASS_BOUND_ALLOWED, "Only one of the upper bounds can be a class"); 418 MAP.put(BOUNDS_NOT_ALLOWED_IF_BOUNDED_BY_TYPE_PARAMETER, "Type parameter cannot have any other bounds if it's bounded by another type parameter"); 419 MAP.put(REPEATED_BOUND, "Type parameter already has this bound"); 420 MAP.put(DYNAMIC_UPPER_BOUND, "Dynamic type can not be used as an upper bound"); 421 MAP.put(USELESS_ELVIS, "Elvis operator (?:) always returns the left operand of non-nullable type {0}", RENDER_TYPE); 422 MAP.put(USELESS_ELVIS_ON_LAMBDA_EXPRESSION, "Left operand of elvis operator (?:) is a lambda expression"); 423 MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME); 424 425 MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES); 426 427 MAP.put(CONSTANT_EXPECTED_TYPE_MISMATCH, "The {0} literal does not conform to the expected type {1}", STRING, RENDER_TYPE); 428 MAP.put(DIVISION_BY_ZERO, "Division by zero"); 429 MAP.put(INTEGER_OVERFLOW, "This operation has led to an overflow"); 430 MAP.put(INT_LITERAL_OUT_OF_RANGE, "The value is out of range"); 431 MAP.put(WRONG_LONG_SUFFIX, "Use 'L' instead of 'l'"); 432 MAP.put(FLOAT_LITERAL_OUT_OF_RANGE, "The value is out of range"); 433 MAP.put(INCORRECT_CHARACTER_LITERAL, "Incorrect character literal"); 434 MAP.put(EMPTY_CHARACTER_LITERAL, "Empty character literal"); 435 MAP.put(TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL, "Too many characters in a character literal ''{0}''", ELEMENT_TEXT); 436 MAP.put(ILLEGAL_ESCAPE, "Illegal escape: ''{0}''", ELEMENT_TEXT); 437 MAP.put(NULL_FOR_NONNULL_TYPE, "Null can not be a value of a non-null type {0}", RENDER_TYPE); 438 439 MAP.put(ELSE_MISPLACED_IN_WHEN, "'else' entry must be the last one in a when-expression"); 440 MAP.put(COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT, "Deprecated syntax. Use '||' instead of commas in when-condition for 'when' without argument"); 441 442 MAP.put(NO_ELSE_IN_WHEN, "'when' expression must be exhaustive, add necessary {0}", RENDER_WHEN_MISSING_CASES); 443 MAP.put(NON_EXHAUSTIVE_WHEN, "'when' expression on enum is recommended to be exhaustive, add {0}", RENDER_WHEN_MISSING_CASES); 444 445 MAP.put(TYPE_MISMATCH_IN_RANGE, "Type mismatch: incompatible types of range and element checked in it"); 446 MAP.put(CYCLIC_INHERITANCE_HIERARCHY, "There's a cycle in the inheritance hierarchy for this type"); 447 MAP.put(CYCLIC_GENERIC_UPPER_BOUND, "Type parameter has cyclic upper bounds"); 448 449 MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list"); 450 MAP.put(SUPERTYPE_NOT_A_CLASS_OR_INTERFACE, "Only classes and interfaces may serve as supertypes"); 451 MAP.put(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, "Extension function type is not allowed as supertypes"); 452 MAP.put(SUPERTYPE_INITIALIZED_IN_INTERFACE, "Interfaces cannot initialize supertypes"); 453 MAP.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes"); 454 MAP.put(CONSTRUCTOR_IN_INTERFACE, "An interface may not have a constructor"); 455 MAP.put(METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE, "An interface may not implement a method of 'kotlin.Any'"); 456 MAP.put(INTERFACE_WITH_SUPERCLASS, "An interface cannot inherit from a class"); 457 MAP.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice"); 458 MAP.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from"); 459 MAP.put(DATA_CLASS_CANNOT_HAVE_CLASS_SUPERTYPES, "Data class inheritance from other classes is forbidden"); 460 MAP.put(SEALED_SUPERTYPE, "This type is sealed, so it can be inherited by only its own nested classes or objects"); 461 MAP.put(SEALED_SUPERTYPE_IN_LOCAL_CLASS, "Local class cannot extend a sealed class"); 462 MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton"); 463 464 MAP.put(CYCLIC_CONSTRUCTOR_DELEGATION_CALL, "There's a cycle in the delegation calls chain"); 465 MAP.put(CONSTRUCTOR_IN_OBJECT, "Constructors are not allowed for objects"); 466 MAP.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without primary constructor"); 467 MAP.put(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, "Primary constructor call expected"); 468 MAP.put(DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR, "Call to super is not allowed in enum constructor"); 469 MAP.put(PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS, "Primary constructor required for data class"); 470 MAP.put(EXPLICIT_DELEGATION_CALL_REQUIRED, 471 "Explicit 'this' or 'super' call is required. There is no constructor in superclass that can be called without arguments"); 472 473 MAP.put(INSTANCE_ACCESS_BEFORE_SUPER_CALL, "Cannot access ''{0}'' before superclass constructor has been called", NAME); 474 475 MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", STRING); 476 477 MAP.put(SAFE_CALL_IN_QUALIFIER, "Safe call is not allowed for qualifier"); 478 479 MAP.put(NO_TAIL_CALLS_FOUND, "A function is marked as tail-recursive but no tail calls are found"); 480 MAP.put(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION, "A type annotation is required on a value parameter"); 481 MAP.put(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP, "'break' and 'continue' are only allowed inside a loop"); 482 MAP.put(BREAK_OR_CONTINUE_IN_WHEN, "'break' and 'continue' are not allowed in 'when' statements. Consider using labels to continue/break from the outer loop"); 483 MAP.put(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY, "'break' or 'continue' jumps across a function boundary"); 484 MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", STRING); 485 MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", STRING); 486 487 MAP.put(ANONYMOUS_INITIALIZER_IN_INTERFACE, "Anonymous initializers are not allowed in interfaces"); 488 MAP.put(NULLABLE_SUPERTYPE, "A supertype cannot be nullable"); 489 MAP.put(DYNAMIC_SUPERTYPE, "A supertype cannot be dynamic"); 490 MAP.put(REDUNDANT_NULLABLE, "Redundant '?'"); 491 MAP.put(UNSAFE_CALL, "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type {0}", RENDER_TYPE); 492 MAP.put(UNSAFE_IMPLICIT_INVOKE_CALL, "Reference has a nullable type {0}, use explicit '?.invoke()' to make function-like call instead", RENDER_TYPE); 493 MAP.put(AMBIGUOUS_LABEL, "Ambiguous label"); 494 MAP.put(UNSUPPORTED, "Unsupported [{0}]", STRING); 495 MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE); 496 MAP.put(UNNECESSARY_SAFE_CALL, "Unnecessary safe call on a non-null receiver of type {0}", RENDER_TYPE); 497 MAP.put(UNEXPECTED_SAFE_CALL, "Safe-call is not allowed here"); 498 MAP.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE); 499 MAP.put(NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION, "Non-null assertion (!!) is called on a lambda expression"); 500 MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", new Renderer<KtTypeConstraint>() { 501 @NotNull 502 @Override 503 public String render(@NotNull KtTypeConstraint typeConstraint) { 504 //noinspection ConstantConditions 505 return typeConstraint.getSubjectTypeParameterName().getReferencedName(); 506 } 507 }, DECLARATION_NAME); 508 MAP.put(SMARTCAST_IMPOSSIBLE, 509 "Smart cast to ''{0}'' is impossible, because ''{1}'' is a {2}", RENDER_TYPE, STRING, STRING); 510 MAP.put(ALWAYS_NULL, "The result of the expression is always null"); 511 512 MAP.put(MISSING_CONSTRUCTOR_KEYWORD, "Use 'constructor' keyword after modifiers of primary constructor"); 513 514 MAP.put(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY, "Variance annotations are only allowed for type parameters of classes and interfaces"); 515 516 MAP.put(DEPRECATED_TYPE_PARAMETER_SYNTAX, "Type parameters must be placed before the name of the function"); 517 518 MAP.put(MISPLACED_TYPE_PARAMETER_CONSTRAINTS, "If a type parameter has multiple constraints, they all need to be placed in the 'where' clause"); 519 520 MAP.put(TYPE_VARIANCE_CONFLICT, "Type parameter {0} is declared as ''{1}'' but occurs in ''{2}'' position in type {3}", 521 new MultiRenderer<VarianceConflictDiagnosticData>() { 522 @NotNull 523 @Override 524 public String[] render(@NotNull VarianceConflictDiagnosticData data) { 525 return new String[] { 526 NAME.render(data.getTypeParameter()), 527 RENDER_POSITION_VARIANCE.render(data.getTypeParameter().getVariance()), 528 RENDER_POSITION_VARIANCE.render(data.getOccurrencePosition()), 529 RENDER_TYPE.render(data.getContainingType()) 530 }; 531 } 532 }); 533 534 MAP.put(FINITE_BOUNDS_VIOLATION, "This type parameter violates the Finite Bound Restriction"); 535 MAP.put(FINITE_BOUNDS_VIOLATION_IN_JAVA, "Violation of Finite Bound Restriction for {0}", STRING); 536 MAP.put(EXPANSIVE_INHERITANCE, "This type parameter violates the Non-Expansive Inheritance Restriction"); 537 MAP.put(EXPANSIVE_INHERITANCE_IN_JAVA, "Violation of Non-Expansive Inheritance Restriction for {0}", STRING); 538 MAP.put(REDUNDANT_PROJECTION, "Projection is redundant: the corresponding type parameter of {0} has the same variance", NAME); 539 MAP.put(CONFLICTING_PROJECTION, "Projection is conflicting with variance of the corresponding type parameter of {0}. Remove the projection or replace it with ''*''", NAME); 540 541 MAP.put(TYPE_ARGUMENTS_FOR_OUTER_CLASS_WHEN_NESTED_REFERENCED, "Type arguments for outer class are redundant when nested class is referenced"); 542 543 MAP.put(REIFIED_TYPE_IN_CATCH_CLAUSE, "Reified type is forbidden for catch parameter"); 544 MAP.put(GENERIC_THROWABLE_SUBCLASS, "Subclass of 'kotlin.Throwable' may not have type parameters"); 545 546 MAP.put(TYPE_MISMATCH_IN_FOR_LOOP, "The loop iterates over values of type {0} but the parameter is declared to be {1}", RENDER_TYPE, 547 RENDER_TYPE); 548 MAP.put(TYPE_MISMATCH_IN_CONDITION, "Condition must be of type kotlin.Boolean, but is of type {0}", RENDER_TYPE); 549 MAP.put(INCOMPATIBLE_TYPES, "Incompatible types: {0} and {1}", RENDER_TYPE, RENDER_TYPE); 550 MAP.put(IMPLICIT_NOTHING_RETURN_TYPE, "''Nothing'' return type needs to be specified explicitly"); 551 MAP.put(IMPLICIT_NOTHING_PROPERTY_TYPE, "''Nothing'' property type needs to be specified explicitly"); 552 MAP.put(IMPLICIT_INTERSECTION_TYPE, "Inferred type {0} is an intersection, please specify the required type explicitly", RENDER_TYPE); 553 MAP.put(EXPECTED_CONDITION, "Expected condition of type kotlin.Boolean"); 554 555 MAP.put(CANNOT_CHECK_FOR_ERASED, "Cannot check for instance of erased type: {0}", RENDER_TYPE); 556 MAP.put(UNCHECKED_CAST, "Unchecked cast: {0} to {1}", RENDER_TYPE, RENDER_TYPE); 557 558 MAP.put(INCONSISTENT_TYPE_PARAMETER_VALUES, "Type parameter {0} of ''{1}'' has inconsistent values: {2}", NAME, NAME, RENDER_COLLECTION_OF_TYPES); 559 MAP.put(INCONSISTENT_TYPE_PARAMETER_BOUNDS, "Type parameter {0} of ''{1}'' has inconsistent bounds: {2}", NAME, NAME, RENDER_COLLECTION_OF_TYPES); 560 561 MAP.put(EQUALITY_NOT_APPLICABLE, "Operator ''{0}'' cannot be applied to ''{1}'' and ''{2}''", new Renderer<KtSimpleNameExpression>() { 562 @NotNull 563 @Override 564 public String render(@NotNull KtSimpleNameExpression nameExpression) { 565 //noinspection ConstantConditions 566 return nameExpression.getReferencedName(); 567 } 568 }, RENDER_TYPE, RENDER_TYPE); 569 570 MAP.put(SENSELESS_COMPARISON, "Condition ''{0}'' is always ''{1}''", ELEMENT_TEXT, TO_STRING); 571 MAP.put(SENSELESS_NULL_IN_WHEN, "Expression under 'when' is never equal to null"); 572 573 MAP.put(INVALID_IF_AS_EXPRESSION, "'if' must have both main and 'else' branches if used as an expression"); 574 575 MAP.put(OVERRIDING_FINAL_MEMBER, "''{0}'' in ''{1}'' is final and cannot be overridden", NAME, NAME); 576 MAP.put(CANNOT_WEAKEN_ACCESS_PRIVILEGE, "Cannot weaken access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); 577 MAP.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); 578 579 MAP.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, "Return type of ''{0}'' is not a subtype of the return type of the overridden member ''{1}''", 580 NAME, FQ_NAMES_IN_TYPES); 581 MAP.put(RETURN_TYPE_MISMATCH_ON_INHERITANCE, "''{0}'' clashes with ''{1}'': return types are incompatible", 582 SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 583 584 MAP.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, "Type of ''{0}'' is not a subtype of the overridden property ''{1}''", 585 NAME, FQ_NAMES_IN_TYPES); 586 MAP.put(VAR_TYPE_MISMATCH_ON_OVERRIDE, "Type of ''{0}'' doesn''t match the type of the overridden var-property ''{1}''", 587 NAME, FQ_NAMES_IN_TYPES); 588 MAP.put(PROPERTY_TYPE_MISMATCH_ON_INHERITANCE, "''{0}'' clashes with ''{1}'': property types are incompatible", 589 SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 590 MAP.put(VAR_TYPE_MISMATCH_ON_INHERITANCE, "''{0}'' clashes with ''{1}'': property types do not match", 591 SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 592 593 MAP.put(OVERRIDING_FINAL_MEMBER_BY_DELEGATION, "''{0}'' implicitly overrides a final member ''{1}'' by delegation", 594 SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 595 MAP.put(VAR_OVERRIDDEN_BY_VAL_BY_DELEGATION, "val-property ''{0}'' implicitly overrides a var-property ''{1}'' by delegation", 596 SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 597 598 MAP.put(VAR_OVERRIDDEN_BY_VAL, "Var-property {0} cannot be overridden by val-property {1}", FQ_NAMES_IN_TYPES, FQ_NAMES_IN_TYPES); 599 600 MAP.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, "{0} must be declared abstract or implement abstract member {1}", RENDER_CLASS_OR_OBJECT, 601 FQ_NAMES_IN_TYPES); 602 MAP.put(ABSTRACT_CLASS_MEMBER_NOT_IMPLEMENTED, "{0} must be declared abstract or implement abstract base class member {1}", 603 RENDER_CLASS_OR_OBJECT, FQ_NAMES_IN_TYPES); 604 605 MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "{0} must override {1} because it inherits many implementations of it", 606 RENDER_CLASS_OR_OBJECT, FQ_NAMES_IN_TYPES); 607 MAP.put(MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED, "{0} must override {1} because it inherits multiple interface methods of it", 608 RENDER_CLASS_OR_OBJECT, FQ_NAMES_IN_TYPES); 609 610 MAP.put(CONFLICTING_OVERLOADS, "''{0}'' is already defined in {1}", COMPACT_WITH_MODIFIERS, STRING); 611 612 MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. " + 613 "The function '" + OperatorNameConventions.INVOKE.asString() + "()' is not found", 614 ELEMENT_TEXT, new Renderer<KotlinType>() { 615 @NotNull 616 @Override 617 public String render(@NotNull KotlinType type) { 618 if (type.isError()) return ""; 619 return " of type '" + RENDER_TYPE.render(type) + "'"; 620 } 621 }); 622 MAP.put(FUNCTION_CALL_EXPECTED, "Function invocation ''{0}({1})'' expected", ELEMENT_TEXT, new Renderer<Boolean>() { 623 @NotNull 624 @Override 625 public String render(@NotNull Boolean hasValueParameters) { 626 return hasValueParameters ? "..." : ""; 627 } 628 }); 629 MAP.put(NON_TAIL_RECURSIVE_CALL, "Recursive call is not a tail call"); 630 MAP.put(TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED, "Tail recursion optimization inside try/catch/finally is not supported"); 631 632 MAP.put(RESULT_TYPE_MISMATCH, "{0} must return {1} but returns {2}", STRING, RENDER_TYPE, RENDER_TYPE); 633 MAP.put(UNSAFE_INFIX_CALL, 634 "Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. " + 635 "Use '?.'-qualified call instead", 636 STRING, STRING, STRING); 637 638 MAP.put(OVERLOAD_RESOLUTION_AMBIGUITY, "Overload resolution ambiguity: {0}", AMBIGUOUS_CALLS); 639 MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied: {0}", AMBIGUOUS_CALLS); 640 MAP.put(CANNOT_COMPLETE_RESOLVE, "Cannot choose among the following candidates without completing type inference: {0}", AMBIGUOUS_CALLS); 641 MAP.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, "Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: {0}", AMBIGUOUS_CALLS); 642 MAP.put(INVOKE_EXTENSION_ON_NOT_EXTENSION_FUNCTION, "Impossible call as extension because {0} is not an extension function.", ELEMENT_TEXT); 643 MAP.put(INVOKE_ON_EXTENSION_FUNCTION_WITH_EXPLICIT_DISPATCH_RECEIVER, "Such calls are no longer supported, surround callee with parenthesis or pass receiver as first argument"); 644 645 MAP.put(NO_VALUE_FOR_PARAMETER, "No value passed for parameter {0}", NAME); 646 MAP.put(MISSING_RECEIVER, "A receiver of type {0} is required", RENDER_TYPE); 647 MAP.put(NO_RECEIVER_ALLOWED, "No receiver can be passed to this function or property"); 648 649 MAP.put(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS, "Cannot create an instance of an abstract class"); 650 651 MAP.put(TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, "Type inference failed: {0}", TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER); 652 MAP.put(TYPE_INFERENCE_CANNOT_CAPTURE_TYPES, "Type inference failed: {0}", TYPE_INFERENCE_CANNOT_CAPTURE_TYPES_RENDERER); 653 MAP.put(TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER, "Type inference failed: {0}", TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER_RENDERER); 654 MAP.put(TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR, "Type inference failed: {0}", TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR_RENDERER); 655 MAP.put(TYPE_INFERENCE_INCORPORATION_ERROR, "Type inference failed. Please try to specify type arguments explicitly."); 656 MAP.put(TYPE_INFERENCE_ONLY_INPUT_TYPES, "Type inference failed. The value of the type parameter {0} should be mentioned in input types " + 657 "(argument types, receiver type or expected type). Try to specify it explicitly.", NAME); 658 MAP.put(TYPE_INFERENCE_UPPER_BOUND_VIOLATED, "{0}", TYPE_INFERENCE_UPPER_BOUND_VIOLATED_RENDERER); 659 MAP.put(TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, "Type inference failed. Expected type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE); 660 661 MAP.put(TYPE_INFERENCE_FAILED_ON_SPECIAL_CONSTRUCT, "Type inference for control flow expression failed. Please specify its type explicitly."); 662 663 MAP.put(WRONG_NUMBER_OF_TYPE_ARGUMENTS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected", (Renderer) null); 664 MAP.put(NO_TYPE_ARGUMENTS_ON_RHS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected. " + 665 "Use ''{1}'' if you don''t want to pass type arguments", null, STRING); 666 667 MAP.put(TYPE_PARAMETER_AS_REIFIED, "Cannot use ''{0}'' as reified type parameter. Use a class instead.", NAME); 668 MAP.put(REIFIED_TYPE_PARAMETER_NO_INLINE, "Only type parameters of inline functions can be reified"); 669 MAP.put(REIFIED_TYPE_FORBIDDEN_SUBSTITUTION, "Cannot use ''{0}'' as reified type parameter", RENDER_TYPE); 670 MAP.put(REIFIED_TYPE_UNSAFE_SUBSTITUTION, "It may be not safe to use ''{0}'' as an argument for a reified type parameter. Use a non-generic type or * if possible", RENDER_TYPE); 671 MAP.put(TYPE_PARAMETERS_NOT_ALLOWED, "Type parameters are not allowed here"); 672 673 MAP.put(TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER, "Type parameter of a property must be used in its receiver type"); 674 675 MAP.put(SUPERTYPES_FOR_ANNOTATION_CLASS, "Annotation class cannot have supertypes"); 676 MAP.put(MISSING_VAL_ON_ANNOTATION_PARAMETER, "'val' keyword is missing on annotation parameter"); 677 MAP.put(ANNOTATION_CLASS_CONSTRUCTOR_CALL, "Annotation class cannot be instantiated"); 678 MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", NAME); 679 MAP.put(ANNOTATION_CLASS_WITH_BODY, "Body is not allowed for annotation class"); 680 MAP.put(INVALID_TYPE_OF_ANNOTATION_MEMBER, "Invalid type of annotation member"); 681 MAP.put(NULLABLE_TYPE_OF_ANNOTATION_MEMBER, "An annotation parameter cannot be nullable"); 682 MAP.put(ANNOTATION_PARAMETER_MUST_BE_CONST, "An annotation parameter must be a compile-time constant"); 683 MAP.put(ANNOTATION_PARAMETER_MUST_BE_ENUM_CONST, "An enum annotation parameter must be a enum constant"); 684 MAP.put(ANNOTATION_PARAMETER_MUST_BE_KCLASS_LITERAL, "An annotation parameter must be a class literal (T::class)"); 685 MAP.put(ANNOTATION_PARAMETER_DEFAULT_VALUE_MUST_BE_CONSTANT, "Default value of annotation parameter must be a compile-time constant"); 686 687 MAP.put(CONST_VAL_NOT_TOP_LEVEL_OR_OBJECT, "Const 'val' are only allowed on top level or in objects"); 688 MAP.put(CONST_VAL_WITH_DELEGATE, "Const 'val' should not have a delegate"); 689 MAP.put(CONST_VAL_WITH_GETTER, "Const 'val' should not have a getter"); 690 MAP.put(TYPE_CANT_BE_USED_FOR_CONST_VAL, "Const 'val' has type ''{0}''. Only primitives and String are allowed", RENDER_TYPE); 691 MAP.put(CONST_VAL_WITHOUT_INITIALIZER, "Const 'val' should have an initializer"); 692 MAP.put(CONST_VAL_WITH_NON_CONST_INITIALIZER, "Const 'val' initializer should be a constant value"); 693 MAP.put(NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION, "Only 'const val' can be used in constant expressions"); 694 695 MAP.put(DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE, "An overriding function is not allowed to specify default values for its parameters"); 696 697 698 String multipleDefaultsMessage = "More than one overridden descriptor declares a default value for ''{0}''. " + 699 "As the compiler can not make sure these values agree, this is not allowed."; 700 MAP.put(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES, multipleDefaultsMessage, FQ_NAMES_IN_TYPES); 701 MAP.put(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE, multipleDefaultsMessage, FQ_NAMES_IN_TYPES); 702 703 MAP.put(PARAMETER_NAME_CHANGED_ON_OVERRIDE, "The corresponding parameter in the supertype ''{0}'' is named ''{1}''. " + 704 "This may cause problems when calling this function with named arguments.", NAME, NAME); 705 706 MAP.put(DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES, 707 "Names of the parameter #{1} conflict in the following members of supertypes: ''{0}''. " + 708 "This may cause problems when calling this function with named arguments.", commaSeparated(FQ_NAMES_IN_TYPES), TO_STRING); 709 710 MAP.put(NAME_FOR_AMBIGUOUS_PARAMETER, "Named argument is not allowed for a parameter with an ambiguous name"); 711 712 MAP.put(DATA_CLASS_WITHOUT_PARAMETERS, "Data class must have at least one primary constructor parameter"); 713 MAP.put(DATA_CLASS_VARARG_PARAMETER, "Primary constructor vararg parameters are forbidden for data classes"); 714 MAP.put(DATA_CLASS_NOT_PROPERTY_PARAMETER, "Data class primary constructor must have only property (val / var) parameters"); 715 716 MAP.put(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED, "Right-hand side has anonymous type. Please specify type explicitly", TO_STRING); 717 718 MAP.put(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED, 719 "''{0}'' is a member and an extension at the same time. References to such elements are not allowed", NAME); 720 MAP.put(CALLABLE_REFERENCE_LHS_NOT_A_CLASS, "Left-hand side of a callable reference cannot be a type parameter"); 721 MAP.put(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS, 722 "Left-hand side of a callable reference with a receiver parameter cannot be empty. " + 723 "Please specify the type of the receiver before '::' explicitly"); 724 MAP.put(CALLABLE_REFERENCE_TO_OBJECT_MEMBER, "Callable references to object members are not supported"); 725 MAP.put(CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR, "Annotation class cannot be instantiated"); 726 727 MAP.put(CLASS_LITERAL_LHS_NOT_A_CLASS, "Only classes are allowed on the left hand side of a class literal"); 728 MAP.put(ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT, "kotlin.Array class literal requires a type argument, please specify one in angle brackets"); 729 730 //Inline 731 MAP.put(NON_PUBLIC_CALL_FROM_PUBLIC_INLINE, "Public-API inline function cannot access non-public-API ''{0}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 732 MAP.put(PRIVATE_CLASS_MEMBER_FROM_INLINE, "Non-private inline function cannot access members of private classes: ''{0}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 733 MAP.put(NOT_YET_SUPPORTED_IN_INLINE, "''{0}'' construction is not yet supported in inline functions", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); 734 MAP.put(DECLARATION_CANT_BE_INLINED, "''inline'' modifier is not allowed on virtual members. Only private or final members can be inlined"); 735 MAP.put(NOTHING_TO_INLINE, "Expected performance impact of inlining ''{0}'' can be insignificant. Inlining works best for functions with lambda parameters", SHORT_NAMES_IN_TYPES); 736 MAP.put(USAGE_IS_NOT_INLINABLE, "Illegal usage of inline-parameter ''{0}'' in ''{1}''. Add ''noinline'' modifier to the parameter declaration", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); 737 MAP.put(NULLABLE_INLINE_PARAMETER, "Inline-parameter ''{0}'' of ''{1}'' must not be nullable. Add ''noinline'' modifier to the parameter declaration or make its type not nullable", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); 738 MAP.put(RECURSION_IN_INLINE, "Inline function ''{1}'' cannot be recursive", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); 739 //Inline non locals 740 MAP.put(NON_LOCAL_RETURN_NOT_ALLOWED, "Can''t inline ''{0}'' here: it may contain non-local returns. Add ''crossinline'' modifier to parameter declaration ''{0}''", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 741 MAP.put(INLINE_CALL_CYCLE, "The ''{0}'' invocation is a part of inline cycle", NAME); 742 MAP.put(NON_LOCAL_RETURN_IN_DISABLED_INLINE, "Non-local returns are not allowed with inlining disabled"); 743 744 MAP.setImmutable(); 745 746 for (Field field : Errors.class.getFields()) { 747 if (Modifier.isStatic(field.getModifiers())) { 748 try { 749 Object fieldValue = field.get(null); 750 if (fieldValue instanceof DiagnosticFactory) { 751 if (MAP.get((DiagnosticFactory<?>) fieldValue) == null) { 752 throw new IllegalStateException("No default diagnostic renderer is provided for " + ((DiagnosticFactory<?>)fieldValue).getName()); 753 } 754 } 755 } 756 catch (IllegalAccessException e) { 757 throw new IllegalStateException(e); 758 } 759 } 760 } 761 } 762 763 private DefaultErrorMessages() { 764 } 765 }