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.jvm.functions.Function1; 021 import org.jetbrains.annotations.NotNull; 022 import org.jetbrains.annotations.Nullable; 023 import org.jetbrains.annotations.TestOnly; 024 import org.jetbrains.kotlin.diagnostics.Diagnostic; 025 import org.jetbrains.kotlin.diagnostics.DiagnosticFactory; 026 import org.jetbrains.kotlin.diagnostics.Errors; 027 import org.jetbrains.kotlin.lexer.JetKeywordToken; 028 import org.jetbrains.kotlin.lexer.JetModifierKeywordToken; 029 import org.jetbrains.kotlin.psi.JetExpression; 030 import org.jetbrains.kotlin.psi.JetSimpleNameExpression; 031 import org.jetbrains.kotlin.psi.JetTypeConstraint; 032 import org.jetbrains.kotlin.renderer.MultiRenderer; 033 import org.jetbrains.kotlin.renderer.Renderer; 034 import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker.VarianceConflictDiagnosticData; 035 import org.jetbrains.kotlin.types.JetType; 036 import org.jetbrains.kotlin.types.expressions.OperatorConventions; 037 import org.jetbrains.kotlin.util.MappedExtensionProvider; 038 039 import java.lang.reflect.Field; 040 import java.lang.reflect.Modifier; 041 import java.util.ArrayList; 042 import java.util.Collection; 043 import java.util.List; 044 045 import static org.jetbrains.kotlin.diagnostics.Errors.*; 046 import static org.jetbrains.kotlin.diagnostics.rendering.Renderers.*; 047 import static org.jetbrains.kotlin.renderer.DescriptorRenderer.*; 048 049 public class DefaultErrorMessages { 050 051 public interface Extension { 052 ExtensionPointName<Extension> EP_NAME = ExtensionPointName.create("org.jetbrains.kotlin.defaultErrorMessages"); 053 054 @NotNull 055 DiagnosticFactoryToRendererMap getMap(); 056 } 057 058 private static final DiagnosticFactoryToRendererMap MAP = new DiagnosticFactoryToRendererMap(); 059 private static final MappedExtensionProvider<Extension, List<DiagnosticFactoryToRendererMap>> RENDERER_MAPS = MappedExtensionProvider.create( 060 Extension.EP_NAME, 061 new Function1<List<? extends Extension>, List<DiagnosticFactoryToRendererMap>>() { 062 @Override 063 public List<DiagnosticFactoryToRendererMap> invoke(List<? extends Extension> extensions) { 064 List<DiagnosticFactoryToRendererMap> result = new ArrayList<DiagnosticFactoryToRendererMap>(extensions.size() + 1); 065 for (Extension extension : extensions) { 066 result.add(extension.getMap()); 067 } 068 result.add(MAP); 069 return result; 070 } 071 }); 072 073 @NotNull 074 public static String render(@NotNull Diagnostic diagnostic) { 075 for (DiagnosticFactoryToRendererMap map : RENDERER_MAPS.get()) { 076 DiagnosticRenderer renderer = map.get(diagnostic.getFactory()); 077 if (renderer != null) { 078 //noinspection unchecked 079 return renderer.render(diagnostic); 080 } 081 } 082 throw new IllegalArgumentException("Don't know how to render diagnostic of type " + diagnostic.getFactory().getName()); 083 } 084 085 @TestOnly 086 @Nullable 087 public static DiagnosticRenderer getRendererForDiagnostic(@NotNull Diagnostic diagnostic) { 088 for (DiagnosticFactoryToRendererMap map : RENDERER_MAPS.get()) { 089 DiagnosticRenderer renderer = map.get(diagnostic.getFactory()); 090 091 if (renderer != null) return renderer; 092 } 093 094 return null; 095 } 096 097 static { 098 MAP.put(UNRESOLVED_REFERENCE, "Unresolved reference: {0}", ELEMENT_TEXT); 099 100 MAP.put(INVISIBLE_REFERENCE, "Cannot access ''{0}'': it is ''{1}'' in ''{2}''", NAME, TO_STRING, NAME); 101 MAP.put(INVISIBLE_MEMBER, "Cannot access ''{0}'': it is ''{1}'' in ''{2}''", NAME, TO_STRING, NAME); 102 103 MAP.put(REDECLARATION, "Redeclaration: {0}", STRING); 104 MAP.put(NAME_SHADOWING, "Name shadowed: {0}", STRING); 105 106 MAP.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE); 107 MAP.put(INCOMPATIBLE_MODIFIERS, "Incompatible modifiers: ''{0}''", new Renderer<Collection<JetModifierKeywordToken>>() { 108 @NotNull 109 @Override 110 public String render(@NotNull Collection<JetModifierKeywordToken> tokens) { 111 StringBuilder sb = new StringBuilder(); 112 for (JetKeywordToken token : tokens) { 113 if (sb.length() != 0) { 114 sb.append(" "); 115 } 116 sb.append(token.getValue()); 117 } 118 return sb.toString(); 119 } 120 }); 121 MAP.put(ILLEGAL_MODIFIER, "Illegal modifier ''{0}''", TO_STRING); 122 MAP.put(REPEATED_MODIFIER, "Repeated ''{0}''", TO_STRING); 123 MAP.put(INAPPLICABLE_ANNOTATION, "This annotation is only applicable to top level functions"); 124 125 MAP.put(REDUNDANT_MODIFIER, "Modifier ''{0}'' is redundant because ''{1}'' is present", TO_STRING, TO_STRING); 126 MAP.put(ABSTRACT_MODIFIER_IN_TRAIT, "Modifier ''abstract'' is redundant in interface"); 127 MAP.put(OPEN_MODIFIER_IN_TRAIT, "Modifier ''open'' is redundant in interface"); 128 MAP.put(OPEN_MODIFIER_IN_ENUM, "Modifier ''open'' is not applicable for enum class"); 129 MAP.put(ABSTRACT_MODIFIER_IN_ENUM, "Modifier ''abstract'' is not applicable for enum class"); 130 MAP.put(ILLEGAL_ENUM_ANNOTATION, "Annotation ''enum'' is only applicable for class"); 131 MAP.put(REDUNDANT_MODIFIER_IN_GETTER, "Visibility modifiers are redundant in getter"); 132 MAP.put(TRAIT_CAN_NOT_BE_FINAL, "Interface cannot be final"); 133 MAP.put(TYPE_PARAMETERS_IN_ENUM, "Enum class cannot have type parameters"); 134 MAP.put(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM, 135 "Type checking has run into a recursive problem. Easiest workaround: specify types of your declarations explicitly"); // TODO: message 136 MAP.put(RETURN_NOT_ALLOWED, "'return' is not allowed here"); 137 MAP.put(PROJECTION_IN_IMMEDIATE_ARGUMENT_TO_SUPERTYPE, "Projections are not allowed for immediate arguments of a supertype"); 138 MAP.put(LABEL_NAME_CLASH, "There is more than one label with such a name in this scope"); 139 MAP.put(EXPRESSION_EXPECTED_PACKAGE_FOUND, "Expression expected, but a package name found"); 140 141 MAP.put(CANNOT_IMPORT_FROM_ELEMENT, "Cannot import from ''{0}''", NAME); 142 MAP.put(CANNOT_IMPORT_ON_DEMAND_FROM_SINGLETON, "Cannot import-on-demand from object ''{0}''", NAME); 143 MAP.put(CANNOT_BE_IMPORTED, "Cannot import ''{0}'', functions and properties can be imported only from packages", NAME); 144 MAP.put(CONFLICTING_IMPORT, "Conflicting import, imported name ''{0}'' is ambiguous", STRING); 145 MAP.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, "This class shouldn''t be used in Kotlin. Use {0} instead.", CLASSES_OR_SEPARATED); 146 147 MAP.put(CANNOT_INFER_PARAMETER_TYPE, "Cannot infer a type for this parameter. Please specify it explicitly."); 148 149 MAP.put(NO_BACKING_FIELD_ABSTRACT_PROPERTY, "This property doesn't have a backing field, because it's abstract"); 150 MAP.put(NO_BACKING_FIELD_CUSTOM_ACCESSORS, 151 "This property doesn't have a backing field, because it has custom accessors without reference to the backing field"); 152 MAP.put(INACCESSIBLE_BACKING_FIELD, "The backing field is not accessible here"); 153 MAP.put(NOT_PROPERTY_BACKING_FIELD, "The referenced variable is not a property and doesn't have backing field"); 154 155 MAP.put(MIXING_NAMED_AND_POSITIONED_ARGUMENTS, "Mixing named and positioned arguments is not allowed"); 156 MAP.put(ARGUMENT_PASSED_TWICE, "An argument is already passed for this parameter"); 157 MAP.put(NAMED_PARAMETER_NOT_FOUND, "Cannot find a parameter with this name: {0}", ELEMENT_TEXT); 158 MAP.put(NAMED_ARGUMENTS_NOT_ALLOWED, "Named arguments are not allowed for {0}", new Renderer<BadNamedArgumentsTarget>() { 159 @NotNull 160 @Override 161 public String render(@NotNull BadNamedArgumentsTarget target) { 162 switch (target) { 163 case NON_KOTLIN_FUNCTION: 164 return "non-Kotlin functions"; 165 case INVOKE_ON_FUNCTION_TYPE: 166 return "function types"; 167 default: 168 throw new AssertionError(target); 169 } 170 } 171 }); 172 173 MAP.put(VARARG_OUTSIDE_PARENTHESES, "Passing value as a vararg is only allowed inside a parenthesized argument list"); 174 MAP.put(NON_VARARG_SPREAD, "The spread operator (*foo) may only be applied in a vararg position"); 175 176 MAP.put(MANY_FUNCTION_LITERAL_ARGUMENTS, "Only one function literal is allowed outside a parenthesized argument list"); 177 MAP.put(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER, "This property must either have a type annotation, be initialized or be delegated"); 178 MAP.put(VARIABLE_WITH_NO_TYPE_NO_INITIALIZER, "This variable must either have a type annotation or be initialized"); 179 180 MAP.put(INITIALIZER_REQUIRED_FOR_MULTIDECLARATION, "Initializer required for multi-declaration"); 181 MAP.put(COMPONENT_FUNCTION_MISSING, "Multi-declaration initializer of type {1} must have a ''{0}()'' function", TO_STRING, RENDER_TYPE); 182 MAP.put(COMPONENT_FUNCTION_AMBIGUITY, "Function ''{0}()'' is ambiguous for this expression: {1}", TO_STRING, AMBIGUOUS_CALLS); 183 MAP.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, "''{0}()'' function returns ''{1}'', but ''{2}'' is expected", 184 TO_STRING, RENDER_TYPE, RENDER_TYPE); 185 186 MAP.put(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, "This property cannot be declared abstract"); 187 MAP.put(ABSTRACT_PROPERTY_WITH_INITIALIZER, "Property with initializer cannot be abstract"); 188 MAP.put(ABSTRACT_PROPERTY_WITH_GETTER, "Property with getter implementation cannot be abstract"); 189 MAP.put(ABSTRACT_PROPERTY_WITH_SETTER, "Property with setter implementation cannot be abstract"); 190 191 MAP.put(ABSTRACT_DELEGATED_PROPERTY, "Delegated property cannot be abstract"); 192 MAP.put(ACCESSOR_FOR_DELEGATED_PROPERTY, "Delegated property cannot have accessors with non-default implementations"); 193 MAP.put(DELEGATED_PROPERTY_IN_TRAIT, "Delegated properties are not allowed in interfaces"); 194 MAP.put(LOCAL_VARIABLE_WITH_DELEGATE, "Local variables are not allowed to have delegates"); 195 196 MAP.put(PACKAGE_MEMBER_CANNOT_BE_PROTECTED, "Package member cannot be protected"); 197 198 MAP.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, "Getter visibility must be the same as property visibility"); 199 MAP.put(BACKING_FIELD_IN_TRAIT, "Property in an interface cannot have a backing field"); 200 MAP.put(MUST_BE_INITIALIZED, "Property must be initialized"); 201 MAP.put(MUST_BE_INITIALIZED_OR_BE_ABSTRACT, "Property must be initialized or be abstract"); 202 MAP.put(PROPERTY_INITIALIZER_IN_TRAIT, "Property initializers are not allowed in interfaces"); 203 MAP.put(FINAL_PROPERTY_IN_TRAIT, "Abstract property in an interface cannot be final"); 204 MAP.put(EXTENSION_PROPERTY_WITH_BACKING_FIELD, "Extension property cannot be initialized because it has no backing field"); 205 MAP.put(PROPERTY_INITIALIZER_NO_BACKING_FIELD, "Initializer is not allowed here because this property has no backing field"); 206 MAP.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, "Abstract property ''{0}'' in non-abstract class ''{1}''", STRING, NAME); 207 MAP.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, "Abstract function ''{0}'' in non-abstract class ''{1}''", STRING, NAME); 208 MAP.put(ABSTRACT_FUNCTION_WITH_BODY, "A function ''{0}'' with body cannot be abstract", NAME); 209 MAP.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without a body must be abstract", NAME); 210 MAP.put(FINAL_FUNCTION_WITH_NO_BODY, "Function ''{0}'' without body cannot be final", NAME); 211 212 MAP.put(NON_MEMBER_FUNCTION_NO_BODY, "Function ''{0}'' must have a body", NAME); 213 MAP.put(FUNCTION_DECLARATION_WITH_NO_NAME, "Function declaration must have a name"); 214 MAP.put(FUNCTION_EXPRESSION_WITH_NAME, "Function expressions with names are deprecated"); 215 MAP.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, "\"open\" has no effect in a final class"); 216 217 MAP.put(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, "Public or protected member should have specified type"); 218 219 MAP.put(FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE, "A function expression is not allowed to specify default values for its parameters"); 220 MAP.put(USELESS_VARARG_ON_PARAMETER, "Vararg on this parameter is useless"); 221 MAP.put(DEPRECATED_LAMBDA_SYNTAX, 222 "This syntax for lambda is deprecated. Use short lambda notation {a[: Int], b[: String] -> ...} or function expression instead."); 223 224 MAP.put(PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT, "Projections are not allowed on type arguments of functions and properties"); 225 MAP.put(SUPERTYPE_NOT_INITIALIZED, "This type has a constructor, and thus must be initialized here"); 226 MAP.put(NOTHING_TO_OVERRIDE, "''{0}'' overrides nothing", NAME); 227 MAP.put(VIRTUAL_MEMBER_HIDDEN, "''{0}'' hides member of supertype ''{2}'' and needs ''override'' modifier", NAME, NAME, NAME); 228 229 MAP.put(DATA_CLASS_OVERRIDE_CONFLICT, "Function ''{0}'' generated for the data class conflicts with member of supertype ''{1}''", NAME, NAME); 230 231 MAP.put(CANNOT_OVERRIDE_INVISIBLE_MEMBER, "''{0}'' has no access to ''{1}'', so it cannot override it", FQ_NAMES_IN_TYPES, 232 FQ_NAMES_IN_TYPES); 233 MAP.put(CANNOT_INFER_VISIBILITY, "Cannot infer visibility for ''{0}''. Please specify it explicitly", COMPACT); 234 235 MAP.put(ENUM_ENTRY_SHOULD_BE_INITIALIZED, "Missing delegation specifier ''{0}''", NAME); 236 MAP.put(ENUM_ENTRY_ILLEGAL_TYPE, "The type constructor of enum entry should be ''{0}''", NAME); 237 238 MAP.put(UNINITIALIZED_VARIABLE, "Variable ''{0}'' must be initialized", NAME); 239 MAP.put(UNINITIALIZED_PARAMETER, "Parameter ''{0}'' is uninitialized here", NAME); 240 MAP.put(UNUSED_VARIABLE, "Variable ''{0}'' is never used", NAME); 241 MAP.put(UNUSED_PARAMETER, "Parameter ''{0}'' is never used", NAME); 242 MAP.put(ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE, "Variable ''{0}'' is assigned but never accessed", NAME); 243 MAP.put(VARIABLE_WITH_REDUNDANT_INITIALIZER, "Variable ''{0}'' initializer is redundant", NAME); 244 MAP.put(UNUSED_VALUE, "The value ''{0}'' assigned to ''{1}'' is never used", ELEMENT_TEXT, FQ_NAMES_IN_TYPES); 245 MAP.put(UNUSED_CHANGED_VALUE, "The value changed at ''{0}'' is never used", ELEMENT_TEXT); 246 MAP.put(UNUSED_EXPRESSION, "The expression is unused"); 247 MAP.put(UNUSED_FUNCTION_LITERAL, "The function literal is unused. If you mean block, you can use 'run { ... }'"); 248 249 MAP.put(VAL_REASSIGNMENT, "Val cannot be reassigned", NAME); 250 MAP.put(SETTER_PROJECTED_OUT, "Setter for ''{0}'' is removed by type projection", NAME); 251 MAP.put(INVISIBLE_SETTER, "Cannot assign to ''{0}'': the setter is ''{1}'' in ''{2}''", NAME, TO_STRING, NAME); 252 MAP.put(INITIALIZATION_BEFORE_DECLARATION, "Variable cannot be initialized before declaration", NAME); 253 MAP.put(VARIABLE_EXPECTED, "Variable expected"); 254 255 MAP.put(VAL_OR_VAR_ON_LOOP_PARAMETER, "''{0}'' on loop parameter is not allowed", TO_STRING); 256 MAP.put(VAL_OR_VAR_ON_FUN_PARAMETER, "''{0}'' on function parameter is not allowed", TO_STRING); 257 MAP.put(VAL_OR_VAR_ON_CATCH_PARAMETER, "''{0}'' on catch parameter is not allowed", TO_STRING); 258 MAP.put(VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER, "''{0}'' on secondary constructor parameter is not allowed", TO_STRING); 259 260 MAP.put(INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER, 261 "This property has a custom setter, so initialization using backing field required", NAME); 262 MAP.put(INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER, 263 "Setter of this property can be overridden, so initialization using backing field required", NAME); 264 265 MAP.put(UNREACHABLE_CODE, "Unreachable code", TO_STRING); 266 267 MAP.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class"); 268 MAP.put(COMPANION_OBJECT_NOT_ALLOWED, "A companion object is not allowed here"); 269 270 MAP.put(DEPRECATED_SYMBOL, "''{0}'' is deprecated.", DEPRECATION); 271 MAP.put(DEPRECATED_SYMBOL_WITH_MESSAGE, "''{0}'' is deprecated. {1}", DEPRECATION, STRING); 272 273 MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME); 274 MAP.put(LOCAL_ENUM_NOT_ALLOWED, "Enum class ''{0}'' cannot be local", NAME); 275 MAP.put(ENUM_ENTRY_USES_DEPRECATED_OR_NO_DELIMITER, "Enum entry ''{0}'' should have a correct delimiter ''{1}'' after it", NAME, STRING); 276 MAP.put(ENUM_ENTRY_USES_DEPRECATED_SUPER_CONSTRUCTOR, "Enum entry ''{0}'' uses deprecated super constructor syntax, use ENTRY(arguments) instead", NAME); 277 MAP.put(ENUM_ENTRY_AFTER_ENUM_MEMBER, "Enum entry ''{0}'' is not allowed after a member", NAME); 278 MAP.put(ENUM_CLASS_CONSTRUCTOR_CALL, "Enum types cannot be instantiated"); 279 280 MAP.put(DELEGATION_IN_TRAIT, "Interfaces cannot use delegation"); 281 MAP.put(DELEGATION_NOT_TO_TRAIT, "Only interfaces can be delegated to"); 282 MAP.put(DEPRECATED_TRAIT_KEYWORD, "'trait' keyword is deprecated, use 'interface' instead"); 283 MAP.put(UNMET_TRAIT_REQUIREMENT, "Super interface ''{0}'' requires subclasses to extend ''{1}''", NAME, NAME); 284 MAP.put(NO_CONSTRUCTOR, "This class does not have a constructor"); 285 MAP.put(NOT_A_CLASS, "Not a class"); 286 MAP.put(ILLEGAL_ESCAPE_SEQUENCE, "Illegal escape sequence"); 287 288 MAP.put(LOCAL_EXTENSION_PROPERTY, "Local extension properties are not allowed"); 289 MAP.put(LOCAL_VARIABLE_WITH_GETTER, "Local variables are not allowed to have getters"); 290 MAP.put(LOCAL_VARIABLE_WITH_SETTER, "Local variables are not allowed to have setters"); 291 MAP.put(VAL_WITH_SETTER, "A 'val'-property cannot have a setter"); 292 293 MAP.put(NO_GET_METHOD, "No get method providing array access"); 294 MAP.put(NO_SET_METHOD, "No set method providing array access"); 295 296 MAP.put(INC_DEC_SHOULD_NOT_RETURN_UNIT, "Functions inc(), dec() shouldn't return Unit to be used by operators ++, --"); 297 MAP.put(ASSIGNMENT_OPERATOR_SHOULD_RETURN_UNIT, "Function ''{0}'' should return Unit to be used by corresponding operator ''{1}''", 298 NAME, ELEMENT_TEXT); 299 MAP.put(ASSIGN_OPERATOR_AMBIGUITY, "Assignment operators ambiguity: {0}", AMBIGUOUS_CALLS); 300 301 MAP.put(EQUALS_MISSING, "No method 'equals(kotlin.Any?): kotlin.Boolean' available"); 302 MAP.put(ASSIGNMENT_IN_EXPRESSION_CONTEXT, "Assignments are not expressions, and only expressions are allowed in this context"); 303 MAP.put(PACKAGE_IS_NOT_AN_EXPRESSION, "'package' is not an expression, it can only be used on the left-hand side of a dot ('.')"); 304 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); 305 MAP.put(SUPER_CANT_BE_EXTENSION_RECEIVER, "''{0}'' is not an expression, it can not be used as a receiver for extension functions", STRING); 306 MAP.put(DECLARATION_IN_ILLEGAL_CONTEXT, "Declarations are not allowed in this position"); 307 MAP.put(SETTER_PARAMETER_WITH_DEFAULT_VALUE, "Setter parameters cannot have default values"); 308 MAP.put(NO_THIS, "'this' is not defined in this context"); 309 MAP.put(SUPER_NOT_AVAILABLE, "No supertypes are accessible in this context"); 310 MAP.put(SUPERCLASS_NOT_ACCESSIBLE_FROM_TRAIT, "Superclass is not accessible from interface"); 311 MAP.put(AMBIGUOUS_SUPER, "Many supertypes available, please specify the one you mean in angle brackets, e.g. 'super<Foo>'"); 312 MAP.put(ABSTRACT_SUPER_CALL, "Abstract member cannot be accessed directly"); 313 MAP.put(NOT_A_SUPERTYPE, "Not a supertype"); 314 MAP.put(TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, "Type arguments do not need to be specified in a 'super' qualifier"); 315 MAP.put(DEPRECATED_STATIC_ASSERT, "Static type assertions are deprecated, consider using a cast instead"); 316 MAP.put(USELESS_CAST, "No cast needed"); 317 MAP.put(CAST_NEVER_SUCCEEDS, "This cast can never succeed"); 318 MAP.put(DYNAMIC_NOT_ALLOWED, "Dynamic types are not allowed in this position"); 319 MAP.put(USELESS_NULLABLE_CHECK, "Non-null type is checked for instance of nullable type"); 320 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); 321 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); 322 MAP.put(NO_COMPANION_OBJECT, "Please specify constructor invocation; classifier ''{0}'' does not have a companion object", NAME); 323 MAP.put(TYPE_PARAMETER_IS_NOT_AN_EXPRESSION, "Type parameter ''{0}'' is not an expression", NAME); 324 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); 325 MAP.put(NO_GENERICS_IN_SUPERTYPE_SPECIFIER, "Generic arguments of the base type must be specified"); 326 MAP.put(NESTED_CLASS_ACCESSED_VIA_INSTANCE_REFERENCE, "Nested {0} accessed via instance reference", RENDER_CLASS_OR_OBJECT_NAME); 327 MAP.put(NESTED_CLASS_SHOULD_BE_QUALIFIED, "Nested {0} should be qualified as ''{1}''", RENDER_CLASS_OR_OBJECT_NAME, TO_STRING); 328 329 MAP.put(INACCESSIBLE_OUTER_CLASS_EXPRESSION, "Expression is inaccessible from a nested class ''{0}'', use ''inner'' keyword to make the class inner", NAME); 330 MAP.put(NESTED_CLASS_NOT_ALLOWED, "Nested class is not allowed here, use ''inner'' keyword to make the class inner"); 331 332 MAP.put(INNER_CLASS_IN_TRAIT, "Inner classes are not allowed in interfaces"); 333 MAP.put(INNER_CLASS_IN_OBJECT, "Inner classes are not allowed in objects"); 334 335 MAP.put(HAS_NEXT_MISSING, "hasNext() cannot be called on iterator() of type ''{0}''", RENDER_TYPE); 336 MAP.put(HAS_NEXT_FUNCTION_AMBIGUITY, "hasNext() is ambiguous for iterator() of type ''{0}''", RENDER_TYPE); 337 MAP.put(HAS_NEXT_FUNCTION_NONE_APPLICABLE, "None of the hasNext() functions is applicable for iterator() of type ''{0}''", RENDER_TYPE); 338 MAP.put(HAS_NEXT_FUNCTION_TYPE_MISMATCH, "The ''iterator().hasNext()'' function of the loop range must return kotlin.Boolean, but returns {0}", RENDER_TYPE); 339 340 MAP.put(NEXT_MISSING, "next() cannot be called on iterator() of type ''{0}''", RENDER_TYPE); 341 MAP.put(NEXT_AMBIGUITY, "next() is ambiguous for iterator() of type ''{0}''", RENDER_TYPE); 342 MAP.put(NEXT_NONE_APPLICABLE, "None of the next() functions is applicable for iterator() of type ''{0}''", RENDER_TYPE); 343 344 MAP.put(ITERATOR_MISSING, "For-loop range must have an iterator() method"); 345 MAP.put(ITERATOR_AMBIGUITY, "Method ''iterator()'' is ambiguous for this expression: {0}", AMBIGUOUS_CALLS); 346 347 MAP.put(DELEGATE_SPECIAL_FUNCTION_MISSING, "Missing ''{0}'' method on delegate of type ''{1}''", STRING, RENDER_TYPE); 348 MAP.put(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY, "Overload resolution ambiguity on method ''{0}'': {1}", STRING, AMBIGUOUS_CALLS); 349 MAP.put(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE, "Property delegate must have a ''{0}'' method. None of the following functions is suitable: {1}", 350 STRING, AMBIGUOUS_CALLS); 351 MAP.put(DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH, "The ''{0}'' function of property delegate is expected to return ''{1}'', but returns ''{2}''", 352 STRING, RENDER_TYPE, RENDER_TYPE); 353 MAP.put(DELEGATE_PD_METHOD_NONE_APPLICABLE, "''{0}'' method may be missing. None of the following functions will be called: {1}", STRING, AMBIGUOUS_CALLS); 354 355 MAP.put(COMPARE_TO_TYPE_MISMATCH, "''compareTo()'' must return kotlin.Int, but returns {0}", RENDER_TYPE); 356 357 MAP.put(RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY, 358 "Returns are not allowed for functions with expression body. Use block body in '{...}'"); 359 MAP.put(NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY, "A 'return' expression required in a function with a block body ('{...}')"); 360 MAP.put(RETURN_TYPE_MISMATCH, "This function must return a value of type {0}", RENDER_TYPE); 361 MAP.put(EXPECTED_TYPE_MISMATCH, "Expected a value of type {0}", RENDER_TYPE); 362 MAP.put(ASSIGNMENT_TYPE_MISMATCH, 363 "Expected a value of type {0}. Assignment operation is not an expression, so it does not return any value", RENDER_TYPE); 364 365 MAP.put(EXPECTED_PARAMETER_TYPE_MISMATCH, "Expected parameter of type {0}", RENDER_TYPE); 366 MAP.put(EXPECTED_RETURN_TYPE_MISMATCH, "Expected return type {0}", RENDER_TYPE); 367 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); 368 369 MAP.put(IMPLICIT_CAST_TO_UNIT_OR_ANY, "Type is cast to ''{0}''. Please specify ''{0}'' as expected type, if you mean such cast", 370 RENDER_TYPE); 371 MAP.put(EXPRESSION_EXPECTED, "{0} is not an expression, and only expressions are allowed here", new Renderer<JetExpression>() { 372 @NotNull 373 @Override 374 public String render(@NotNull JetExpression expression) { 375 String expressionType = expression.toString(); 376 return expressionType.substring(0, 1) + 377 expressionType.substring(1).toLowerCase(); 378 } 379 }); 380 381 MAP.put(UPPER_BOUND_VIOLATED, "Type argument is not within its bounds: should be subtype of ''{0}''", RENDER_TYPE, RENDER_TYPE); 382 MAP.put(FINAL_UPPER_BOUND, "''{0}'' is a final type, and thus a value of the type parameter is predetermined", RENDER_TYPE); 383 MAP.put(DYNAMIC_UPPER_BOUND, "Dynamic type can not be used as an upper bound"); 384 MAP.put(USELESS_ELVIS, "Elvis operator (?:) always returns the left operand of non-nullable type {0}", RENDER_TYPE); 385 MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME); 386 387 MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES); 388 389 MAP.put(CONSTANT_EXPECTED_TYPE_MISMATCH, "An {0} literal does not conform to the expected type {1}", STRING, RENDER_TYPE); 390 MAP.put(DIVISION_BY_ZERO, "Division by zero"); 391 MAP.put(INTEGER_OVERFLOW, "This operation has led to an overflow"); 392 MAP.put(INT_LITERAL_OUT_OF_RANGE, "The value is out of range"); 393 MAP.put(WRONG_LONG_SUFFIX, "Use 'L' instead of 'l'"); 394 MAP.put(FLOAT_LITERAL_OUT_OF_RANGE, "The value is out of range"); 395 MAP.put(INCORRECT_CHARACTER_LITERAL, "Incorrect character literal"); 396 MAP.put(EMPTY_CHARACTER_LITERAL, "Empty character literal"); 397 MAP.put(TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL, "Too many characters in a character literal ''{0}''", ELEMENT_TEXT); 398 MAP.put(ILLEGAL_ESCAPE, "Illegal escape: ''{0}''", ELEMENT_TEXT); 399 MAP.put(NULL_FOR_NONNULL_TYPE, "Null can not be a value of a non-null type {0}", RENDER_TYPE); 400 401 MAP.put(ELSE_MISPLACED_IN_WHEN, "'else' entry must be the last one in a when-expression"); 402 403 MAP.put(NO_ELSE_IN_WHEN, "'when' expression must contain 'else' branch"); 404 405 MAP.put(TYPE_MISMATCH_IN_RANGE, "Type mismatch: incompatible types of range and element checked in it"); 406 MAP.put(CYCLIC_INHERITANCE_HIERARCHY, "There's a cycle in the inheritance hierarchy for this type"); 407 408 MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list"); 409 MAP.put(SUPERTYPE_NOT_A_CLASS_OR_TRAIT, "Only classes and interfaces may serve as supertypes"); 410 MAP.put(SUPERTYPE_INITIALIZED_IN_TRAIT, "Interfaces cannot initialize supertypes"); 411 MAP.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes"); 412 MAP.put(CONSTRUCTOR_IN_TRAIT, "An interface may not have a constructor"); 413 MAP.put(TRAIT_WITH_SUPERCLASS, "Specifying a required base class for interface implementations is deprecated"); 414 MAP.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice"); 415 MAP.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from"); 416 MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton"); 417 418 MAP.put(CYCLIC_CONSTRUCTOR_DELEGATION_CALL, "There's a cycle in the delegation calls chain"); 419 MAP.put(CONSTRUCTOR_IN_OBJECT, "Constructors are not allowed for objects"); 420 MAP.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without primary constructor"); 421 MAP.put(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, "Primary constructor call expected"); 422 MAP.put(DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR, "Call to super is not allowed in enum constructor"); 423 MAP.put(PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS, "Primary constructor required for data class"); 424 MAP.put(EXPLICIT_DELEGATION_CALL_REQUIRED, 425 "Explicit 'this' or 'super' call is required. There is no constructor in superclass that can be called without arguments"); 426 427 MAP.put(INSTANCE_ACCESS_BEFORE_SUPER_CALL, "Cannot access ''{0}'' before superclass constructor has been called", NAME); 428 429 MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", STRING); 430 431 MAP.put(NO_TAIL_CALLS_FOUND, "A function is marked as tail-recursive but no tail calls are found"); 432 MAP.put(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION, "A type annotation is required on a value parameter"); 433 MAP.put(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP, "'break' and 'continue' are only allowed inside a loop"); 434 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"); 435 MAP.put(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY, "'break' or 'continue' jumps across a function boundary"); 436 MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", STRING); 437 MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", STRING); 438 439 MAP.put(ANONYMOUS_INITIALIZER_IN_TRAIT, "Anonymous initializers are not allowed in interfaces"); 440 MAP.put(NULLABLE_SUPERTYPE, "A supertype cannot be nullable"); 441 MAP.put(DYNAMIC_SUPERTYPE, "A supertype cannot be dynamic"); 442 MAP.put(REDUNDANT_NULLABLE, "Redundant '?'"); 443 MAP.put(BASE_WITH_NULLABLE_UPPER_BOUND, "''{0}'' has a nullable upper bound. " + 444 "This means that a value of this type may be null. " + 445 "Using ''{0}?'' is likely to mislead the reader", RENDER_TYPE); 446 MAP.put(UNSAFE_CALL, "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type {0}", RENDER_TYPE); 447 MAP.put(AMBIGUOUS_LABEL, "Ambiguous label"); 448 MAP.put(UNSUPPORTED, "Unsupported [{0}]", STRING); 449 MAP.put(EXCEPTION_FROM_ANALYZER, "Internal Error occurred while analyzing this expression:\n{0}", THROWABLE); 450 MAP.put(UNNECESSARY_SAFE_CALL, "Unnecessary safe call on a non-null receiver of type {0}", RENDER_TYPE); 451 MAP.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE); 452 MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", new Renderer<JetTypeConstraint>() { 453 @NotNull 454 @Override 455 public String render(@NotNull JetTypeConstraint typeConstraint) { 456 //noinspection ConstantConditions 457 return typeConstraint.getSubjectTypeParameterName().getReferencedName(); 458 } 459 }, DECLARATION_NAME); 460 MAP.put(SMARTCAST_IMPOSSIBLE, 461 "Smart cast to ''{0}'' is impossible, because ''{1}'' could have changed since the is-check", RENDER_TYPE, STRING); 462 463 MAP.put(MISSING_CONSTRUCTOR_KEYWORD, "Use 'constructor' keyword after modifiers of primary constructor"); 464 465 MAP.put(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY, "Variance annotations are only allowed for type parameters of classes and interfaces"); 466 MAP.put(TYPE_VARIANCE_CONFLICT, "Type parameter {0} is declared as ''{1}'' but occurs in ''{2}'' position in type {3}", 467 new MultiRenderer<VarianceConflictDiagnosticData>() { 468 @NotNull 469 @Override 470 public String[] render(@NotNull VarianceConflictDiagnosticData data) { 471 return new String[] { 472 NAME.render(data.getTypeParameter()), 473 RENDER_POSITION_VARIANCE.render(data.getTypeParameter().getVariance()), 474 RENDER_POSITION_VARIANCE.render(data.getOccurrencePosition()), 475 RENDER_TYPE.render(data.getContainingType()) 476 }; 477 } 478 }); 479 480 MAP.put(REDUNDANT_PROJECTION, "Projection is redundant: the corresponding type parameter of {0} has the same variance", NAME); 481 MAP.put(CONFLICTING_PROJECTION, "Projection is conflicting with variance of the corresponding type parameter of {0}. Remove the projection or replace it with ''*''", NAME); 482 483 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, 484 RENDER_TYPE); 485 MAP.put(TYPE_MISMATCH_IN_CONDITION, "Condition must be of type kotlin.Boolean, but is of type {0}", RENDER_TYPE); 486 MAP.put(INCOMPATIBLE_TYPES, "Incompatible types: {0} and {1}", RENDER_TYPE, RENDER_TYPE); 487 MAP.put(EXPECTED_CONDITION, "Expected condition of type kotlin.Boolean"); 488 489 MAP.put(CANNOT_CHECK_FOR_ERASED, "Cannot check for instance of erased type: {0}", RENDER_TYPE); 490 MAP.put(UNCHECKED_CAST, "Unchecked cast: {0} to {1}", RENDER_TYPE, RENDER_TYPE); 491 492 MAP.put(INCONSISTENT_TYPE_PARAMETER_VALUES, "Type parameter {0} of ''{1}'' has inconsistent values: {2}", NAME, NAME, RENDER_COLLECTION_OF_TYPES); 493 494 MAP.put(EQUALITY_NOT_APPLICABLE, "Operator ''{0}'' cannot be applied to ''{1}'' and ''{2}''", new Renderer<JetSimpleNameExpression>() { 495 @NotNull 496 @Override 497 public String render(@NotNull JetSimpleNameExpression nameExpression) { 498 //noinspection ConstantConditions 499 return nameExpression.getReferencedName(); 500 } 501 }, RENDER_TYPE, RENDER_TYPE); 502 503 MAP.put(SENSELESS_COMPARISON, "Condition ''{0}'' is always ''{1}''", ELEMENT_TEXT, TO_STRING); 504 MAP.put(SENSELESS_NULL_IN_WHEN, "Expression under 'when' is never equal to null"); 505 506 MAP.put(OVERRIDING_FINAL_MEMBER, "''{0}'' in ''{1}'' is final and cannot be overridden", NAME, NAME); 507 MAP.put(CANNOT_WEAKEN_ACCESS_PRIVILEGE, "Cannot weaken access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); 508 MAP.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); 509 510 MAP.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, "Return type of ''{0}'' is not a subtype of the return type of the overridden member ''{1}''", 511 NAME, FQ_NAMES_IN_TYPES); 512 513 MAP.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, "Type of ''{0}'' doesn''t match the type of the overridden var-property ''{1}''", 514 NAME, FQ_NAMES_IN_TYPES); 515 516 MAP.put(VAR_OVERRIDDEN_BY_VAL, "Var-property {0} cannot be overridden by val-property {1}", FQ_NAMES_IN_TYPES, FQ_NAMES_IN_TYPES); 517 518 MAP.put(ABSTRACT_MEMBER_NOT_IMPLEMENTED, "{0} must be declared abstract or implement abstract member {1}", RENDER_CLASS_OR_OBJECT, 519 FQ_NAMES_IN_TYPES); 520 521 MAP.put(MANY_IMPL_MEMBER_NOT_IMPLEMENTED, "{0} must override {1} because it inherits many implementations of it", 522 RENDER_CLASS_OR_OBJECT, FQ_NAMES_IN_TYPES); 523 524 MAP.put(CONFLICTING_OVERLOADS, "''{0}'' is already defined in {1}", COMPACT_WITH_MODIFIERS, STRING); 525 MAP.put(ILLEGAL_PLATFORM_NAME, "Illegal platform name: ''{0}''", STRING); 526 527 MAP.put(FUNCTION_EXPECTED, "Expression ''{0}''{1} cannot be invoked as a function. " + 528 "The function '" + OperatorConventions.INVOKE.asString() + "()' is not found", 529 ELEMENT_TEXT, new Renderer<JetType>() { 530 @NotNull 531 @Override 532 public String render(@NotNull JetType type) { 533 if (type.isError()) return ""; 534 return " of type '" + RENDER_TYPE.render(type) + "'"; 535 } 536 }); 537 MAP.put(FUNCTION_CALL_EXPECTED, "Function invocation ''{0}({1})'' expected", ELEMENT_TEXT, new Renderer<Boolean>() { 538 @NotNull 539 @Override 540 public String render(@NotNull Boolean hasValueParameters) { 541 return hasValueParameters ? "..." : ""; 542 } 543 }); 544 MAP.put(NON_TAIL_RECURSIVE_CALL, "Recursive call is not a tail call"); 545 MAP.put(TAIL_RECURSION_IN_TRY_IS_NOT_SUPPORTED, "Tail recursion optimization inside try/catch/finally is not supported"); 546 547 MAP.put(RESULT_TYPE_MISMATCH, "{0} must return {1} but returns {2}", STRING, RENDER_TYPE, RENDER_TYPE); 548 MAP.put(UNSAFE_INFIX_CALL, 549 "Infix call corresponds to a dot-qualified call ''{0}.{1}({2})'' which is not allowed on a nullable receiver ''{0}''. " + 550 "Use '?.'-qualified call instead", 551 STRING, STRING, STRING); 552 553 MAP.put(OVERLOAD_RESOLUTION_AMBIGUITY, "Overload resolution ambiguity: {0}", AMBIGUOUS_CALLS); 554 MAP.put(NONE_APPLICABLE, "None of the following functions can be called with the arguments supplied: {0}", AMBIGUOUS_CALLS); 555 MAP.put(CANNOT_COMPLETE_RESOLVE, "Cannot choose among the following candidates without completing type inference: {0}", AMBIGUOUS_CALLS); 556 MAP.put(UNRESOLVED_REFERENCE_WRONG_RECEIVER, "Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: {0}", AMBIGUOUS_CALLS); 557 558 MAP.put(NO_VALUE_FOR_PARAMETER, "No value passed for parameter {0}", NAME); 559 MAP.put(MISSING_RECEIVER, "A receiver of type {0} is required", RENDER_TYPE); 560 MAP.put(NO_RECEIVER_ALLOWED, "No receiver can be passed to this function or property"); 561 562 MAP.put(FREE_FUNCTION_CALLED_AS_EXTENSION, "The function cannot be called as an extension function"); 563 564 MAP.put(CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS, "Cannot create an instance of an abstract class"); 565 566 MAP.put(TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, "Type inference failed: {0}", TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS_RENDERER); 567 MAP.put(TYPE_INFERENCE_CANNOT_CAPTURE_TYPES, "Type inference failed: {0}", TYPE_INFERENCE_CANNOT_CAPTURE_TYPES_RENDERER); 568 MAP.put(TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER, "Type inference failed: {0}", TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER_RENDERER); 569 MAP.put(TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH, "Type inference failed: {0}", TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH_RENDERER); 570 MAP.put(TYPE_INFERENCE_UPPER_BOUND_VIOLATED, "{0}", TYPE_INFERENCE_UPPER_BOUND_VIOLATED_RENDERER); 571 MAP.put(TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, "Type inference failed. Expected type mismatch: found: {1} required: {0}", RENDER_TYPE, RENDER_TYPE); 572 573 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); 574 MAP.put(NO_TYPE_ARGUMENTS_ON_RHS, "{0,choice,0#No type arguments|1#Type argument|1<{0,number,integer} type arguments} expected. " + 575 "Use ''{1}'' if you don''t want to pass type arguments", null, STRING); 576 577 MAP.put(TYPE_PARAMETER_AS_REIFIED, "Cannot use ''{0}'' as reified type parameter. Use a class instead.", NAME); 578 MAP.put(REIFIED_TYPE_PARAMETER_NO_INLINE, "Only type parameters of inline functions can be reified"); 579 MAP.put(REIFIED_TYPE_FORBIDDEN_SUBSTITUTION, "Cannot use ''{0}'' as reified type parameter", RENDER_TYPE); 580 MAP.put(TYPE_PARAMETERS_NOT_ALLOWED, "Type parameters are not allowed here"); 581 582 MAP.put(SUPERTYPES_FOR_ANNOTATION_CLASS, "Annotation class cannot have supertypes"); 583 MAP.put(MISSING_VAL_ON_ANNOTATION_PARAMETER, "'val' keyword is missing on annotation parameter"); 584 MAP.put(ANNOTATION_CLASS_CONSTRUCTOR_CALL, "Annotation class cannot be instantiated"); 585 MAP.put(NOT_AN_ANNOTATION_CLASS, "''{0}'' is not an annotation class", NAME); 586 MAP.put(ANNOTATION_CLASS_WITH_BODY, "Body is not allowed for annotation class"); 587 MAP.put(INVALID_TYPE_OF_ANNOTATION_MEMBER, "Invalid type of annotation member"); 588 MAP.put(NULLABLE_TYPE_OF_ANNOTATION_MEMBER, "An annotation parameter cannot be nullable"); 589 MAP.put(JAVA_LANG_CLASS_PARAMETER_IN_ANNOTATION, "java.lang.Class as annotation parameter is deprecated. Use KClass instead"); 590 MAP.put(ILLEGAL_ANNOTATION_KEYWORD, "''annotation'' keyword is only applicable for class"); 591 MAP.put(ANNOTATION_PARAMETER_MUST_BE_CONST, "An annotation parameter must be a compile-time constant"); 592 MAP.put(ANNOTATION_PARAMETER_MUST_BE_ENUM_CONST, "An enum annotation parameter must be a enum constant"); 593 MAP.put(ANNOTATION_PARAMETER_MUST_BE_CLASS_LITERAL, "An annotation parameter must be a `javaClass<T>()` call"); 594 MAP.put(ANNOTATION_PARAMETER_MUST_BE_KCLASS_LITERAL, "An annotation parameter must be a class literal (T::class)"); 595 MAP.put(DEPRECATED_ANNOTATION_SYNTAX, "This syntax for annotations is deprecated. Use '@' before annotation identifier instead"); 596 MAP.put(ANNOTATION_PARAMETER_DEFAULT_VALUE_MUST_BE_CONSTANT, "Default value of annotation parameter must be a compile-time constant"); 597 598 MAP.put(DEFAULT_VALUE_NOT_ALLOWED_IN_OVERRIDE, "An overriding function is not allowed to specify default values for its parameters"); 599 600 601 String multipleDefaultsMessage = "More than one overridden descriptor declares a default value for ''{0}''. " + 602 "As the compiler can not make sure these values agree, this is not allowed."; 603 MAP.put(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES, multipleDefaultsMessage, FQ_NAMES_IN_TYPES); 604 MAP.put(MULTIPLE_DEFAULTS_INHERITED_FROM_SUPERTYPES_WHEN_NO_EXPLICIT_OVERRIDE, multipleDefaultsMessage, FQ_NAMES_IN_TYPES); 605 606 MAP.put(PARAMETER_NAME_CHANGED_ON_OVERRIDE, "The corresponding parameter in the supertype ''{0}'' is named ''{1}''. " + 607 "This may cause problems when calling this function with named arguments.", NAME, NAME); 608 609 MAP.put(DIFFERENT_NAMES_FOR_THE_SAME_PARAMETER_IN_SUPERTYPES, 610 "Names of the parameter #{1} conflict in the following members of supertypes: ''{0}''. " + 611 "This may cause problems when calling this function with named arguments.", commaSeparated(FQ_NAMES_IN_TYPES), TO_STRING); 612 613 MAP.put(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED, "Right-hand side has anonymous type. Please specify type explicitly", TO_STRING); 614 615 MAP.put(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED, 616 "''{0}'' is a member and an extension at the same time. References to such elements are not allowed", NAME); 617 MAP.put(CALLABLE_REFERENCE_LHS_NOT_A_CLASS, "Left hand side of a callable reference cannot be a type parameter"); 618 619 MAP.put(CLASS_LITERAL_LHS_NOT_A_CLASS, "Only classes are allowed on the left hand side of a class literal"); 620 MAP.put(ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT, "kotlin.Array class literal requires a type argument, please specify one in angle brackets"); 621 622 //Inline 623 MAP.put(INVISIBLE_MEMBER_FROM_INLINE, "Cannot access effectively non-public-api ''{0}'' member from effectively public-api ''{1}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 624 MAP.put(NOT_YET_SUPPORTED_IN_INLINE, "''{0}'' construction not yet supported in inline functions", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); 625 MAP.put(DECLARATION_CANT_BE_INLINED, "Inline annotation could be present only on nonvirtual members (private or final)"); 626 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); 627 MAP.put(USAGE_IS_NOT_INLINABLE, "Illegal usage of inline-parameter ''{0}'' in ''{1}''. Annotate the parameter with [noinline]", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); 628 MAP.put(NULLABLE_INLINE_PARAMETER, "Inline-parameter ''{0}'' of ''{1}'' must not be nullable. Annotate the parameter with [noinline] or make not nullable", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); 629 MAP.put(RECURSION_IN_INLINE, "Inline-function ''{1}'' can't be recursive", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); 630 //Inline non Locals 631 MAP.put(NON_LOCAL_RETURN_NOT_ALLOWED, "Can''t inline ''{0}'' here: it may contain non-local returns. Annotate parameter declaration ''{0}'' with ''inlineOptions(ONLY_LOCAL_RETURN)''", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); 632 MAP.put(INLINE_CALL_CYCLE, "The ''{0}'' invocation is a part of inline cycle", NAME); 633 MAP.put(NON_LOCAL_RETURN_IN_DISABLED_INLINE, "Non-local returns are not allowed with inlining disabled"); 634 635 MAP.setImmutable(); 636 637 for (Field field : Errors.class.getFields()) { 638 if (Modifier.isStatic(field.getModifiers())) { 639 try { 640 Object fieldValue = field.get(null); 641 if (fieldValue instanceof DiagnosticFactory) { 642 if (MAP.get((DiagnosticFactory<?>) fieldValue) == null) { 643 throw new IllegalStateException("No default diagnostic renderer is provided for " + ((DiagnosticFactory<?>)fieldValue).getName()); 644 } 645 } 646 } 647 catch (IllegalAccessException e) { 648 throw new IllegalStateException(e); 649 } 650 } 651 } 652 } 653 654 private DefaultErrorMessages() { 655 } 656 }