mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
This presents a regression in diagnostic quality that is definitely worth it not to lie to SILGen about whether a switch is covered or not. At the same time, disable SIL’s unreachable diagnostic for ‘default’ clauses which would previously cause a warning to be emitted if the default was proven to be unreachable. This analysis is incomplete anyways and can be done by Sema in the future if we desire.
318 lines
13 KiB
C++
318 lines
13 KiB
C++
//===--- DiagnosticsSIL.def - Diagnostics Text ------------------*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file defines diagnostics emitted during SIL (dataflow) analysis.
|
|
// Each diagnostic is described using one of three kinds (error, warning, or
|
|
// note) along with a unique identifier, category, options, and text, and is
|
|
// followed by a signature describing the diagnostic argument kinds.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#if !(defined(DIAG) || (defined(ERROR) && defined(WARNING) && defined(NOTE) && defined(REMARK)))
|
|
# error Must define either DIAG or the set {ERROR,WARNING,NOTE,REMARK}
|
|
#endif
|
|
|
|
#ifndef ERROR
|
|
# define ERROR(ID,Options,Text,Signature) \
|
|
DIAG(ERROR,ID,Options,Text,Signature)
|
|
#endif
|
|
|
|
#ifndef WARNING
|
|
# define WARNING(ID,Options,Text,Signature) \
|
|
DIAG(WARNING,ID,Options,Text,Signature)
|
|
#endif
|
|
|
|
#ifndef NOTE
|
|
# define NOTE(ID,Options,Text,Signature) \
|
|
DIAG(NOTE,ID,Options,Text,Signature)
|
|
#endif
|
|
|
|
#ifndef REMARK
|
|
# define REMARK(ID,Options,Text,Signature) \
|
|
DIAG(REMARK,ID,Options,Text,Signature)
|
|
#endif
|
|
|
|
|
|
// SILGen issues.
|
|
ERROR(bridging_module_missing,none,
|
|
"unable to find module '%0' for implicit conversion function '%0.%1'",
|
|
(StringRef, StringRef))
|
|
ERROR(bridging_function_missing,none,
|
|
"unable to find implicit conversion function '%0.%1'",
|
|
(StringRef, StringRef))
|
|
ERROR(bridging_function_overloaded,none,
|
|
"multiple definitions of implicit conversion function '%0.%1'",
|
|
(StringRef, StringRef))
|
|
ERROR(bridging_function_not_function,none,
|
|
"definition of implicit conversion function '%0.%1' is not a function",
|
|
(StringRef, StringRef))
|
|
ERROR(bridging_function_not_correct_type,none,
|
|
"definition of implicit conversion function '%0.%1' is not of the correct"
|
|
" type",
|
|
(StringRef, StringRef))
|
|
ERROR(bridging_objcbridgeable_missing,none,
|
|
"cannot find definition of '_ObjectiveCBridgeable' protocol", ())
|
|
ERROR(bridging_objcbridgeable_broken,none,
|
|
"broken definition of '_ObjectiveCBridgeable' protocol: missing %0",
|
|
(DeclName))
|
|
|
|
ERROR(invalid_sil_builtin,none,
|
|
"INTERNAL ERROR: invalid use of builtin: %0",
|
|
(StringRef))
|
|
ERROR(could_not_find_bridge_type,none,
|
|
"could not find Objective-C bridge type for type %0; "
|
|
"did you forget to import Foundation?", (Type))
|
|
ERROR(could_not_find_pointer_pointee_property,none,
|
|
"could not find 'pointee' property of pointer type %0", (Type))
|
|
|
|
ERROR(writeback_overlap_property,none,
|
|
"inout writeback to computed property %0 occurs in multiple arguments to"
|
|
" call, introducing invalid aliasing", (Identifier))
|
|
ERROR(writeback_overlap_subscript,none,
|
|
"inout writeback through subscript occurs in multiple arguments to call,"
|
|
" introducing invalid aliasing",
|
|
())
|
|
NOTE(writebackoverlap_note,none,
|
|
"concurrent writeback occurred here", ())
|
|
|
|
ERROR(addressonly_type_used_in_multipattern_case,none,
|
|
"matching %select{type '%1'|a protocol value|a generic value}0 in multiple patterns "
|
|
"is not yet supported; use separate cases instead",
|
|
(unsigned, Type))
|
|
|
|
ERROR(inout_argument_alias,none,
|
|
"inout arguments are not allowed to alias each other", ())
|
|
NOTE(previous_inout_alias,none,
|
|
"previous aliasing argument", ())
|
|
|
|
WARNING(exclusivity_access_required_warn,none,
|
|
"overlapping accesses to %0, but "
|
|
"%select{initialization|read|modification|deinitialization}1 requires "
|
|
"exclusive access; "
|
|
"%select{consider copying to a local variable|"
|
|
"consider calling MutableCollection.swapAt(_:_:)}2",
|
|
(StringRef, unsigned, bool))
|
|
|
|
ERROR(exclusivity_access_required,none,
|
|
"overlapping accesses to %0, but "
|
|
"%select{initialization|read|modification|deinitialization}1 requires "
|
|
"exclusive access; "
|
|
"%select{consider copying to a local variable|"
|
|
"consider calling MutableCollection.swapAt(_:_:)}2",
|
|
(StringRef, unsigned, bool))
|
|
|
|
ERROR(exclusivity_access_required_unknown_decl,none,
|
|
"overlapping accesses, but "
|
|
"%select{initialization|read|modification|deinitialization}0 requires "
|
|
"exclusive access; consider copying to a local variable", (unsigned))
|
|
|
|
WARNING(exclusivity_access_required_unknown_decl_warn,none,
|
|
"overlapping accesses, but "
|
|
"%select{initialization|read|modification|deinitialization}0 requires "
|
|
"exclusive access; consider copying to a local variable", (unsigned))
|
|
|
|
NOTE(exclusivity_conflicting_access,none,
|
|
"conflicting access is here", ())
|
|
|
|
ERROR(unsupported_c_function_pointer_conversion,none,
|
|
"C function pointer signature %0 is not compatible with expected type %1",
|
|
(Type, Type))
|
|
|
|
ERROR(objc_selector_malformed,none,"the type ObjectiveC.Selector is malformed",
|
|
())
|
|
|
|
// Definite initialization diagnostics.
|
|
NOTE(variable_defined_here,none,
|
|
"%select{variable|constant}0 defined here", (bool))
|
|
ERROR(variable_used_before_initialized,none,
|
|
"%select{variable|constant}1 '%0' used before being initialized",
|
|
(StringRef, bool))
|
|
ERROR(variable_inout_before_initialized,none,
|
|
"%select{variable|constant}1 '%0' passed by reference before being"
|
|
" initialized", (StringRef, bool))
|
|
ERROR(variable_closure_use_uninit,none,
|
|
"%select{variable|constant}1 '%0' captured by a closure before being"
|
|
" initialized", (StringRef, bool))
|
|
ERROR(self_closure_use_uninit,none,
|
|
"'self' captured by a closure before all members were initialized", ())
|
|
|
|
|
|
ERROR(variable_addrtaken_before_initialized,none,
|
|
"address of %select{variable|constant}1 '%0' taken before it is"
|
|
" initialized", (StringRef, bool))
|
|
ERROR(ivar_not_initialized_at_superinit,none,
|
|
"property '%0' not initialized at super.init call", (StringRef, bool))
|
|
ERROR(ivar_not_initialized_at_implicit_superinit,none,
|
|
"property '%0' not initialized at implicitly generated super.init call",
|
|
(StringRef, bool))
|
|
|
|
ERROR(self_use_before_fully_init,none,
|
|
"'self' used in %select{method call|property access}1 %0 before "
|
|
"%select{all stored properties are initialized|"
|
|
"'super.init' call|"
|
|
"'self.init' call}2", (DeclBaseName, bool, unsigned))
|
|
ERROR(use_of_self_before_fully_init,none,
|
|
"'self' used before all stored properties are initialized", ())
|
|
|
|
|
|
NOTE(stored_property_not_initialized,none,
|
|
"'%0' not initialized", (StringRef))
|
|
|
|
ERROR(selfinit_multiple_times,none,
|
|
"'%select{super|self}0.init' called multiple times in initializer",
|
|
(unsigned))
|
|
ERROR(superselfinit_not_called_before_return,none,
|
|
"'%select{super|self}0.init' isn't called on all paths before returning "
|
|
"from initializer", (unsigned))
|
|
ERROR(self_before_superinit,none,
|
|
"'self' used before 'super.init' call", ())
|
|
ERROR(self_before_selfinit,none,
|
|
"'self' used before 'self.init' call", ())
|
|
ERROR(self_before_selfinit_value_type,none,
|
|
"'self' used before 'self.init' call or assignment to 'self'", ())
|
|
ERROR(self_inside_catch_superselfinit,none,
|
|
"'self' used inside 'catch' block reachable from "
|
|
"%select{super|self}0.init call",
|
|
(unsigned))
|
|
ERROR(return_from_init_without_initing_self,none,
|
|
"return from initializer before 'self.init' call or assignment to 'self'", ())
|
|
ERROR(return_from_init_without_initing_stored_properties,none,
|
|
"return from initializer without initializing all"
|
|
" stored properties", ())
|
|
|
|
ERROR(variable_function_use_uninit,none,
|
|
"%select{variable|constant}1 '%0' used by function definition before"
|
|
" being initialized",
|
|
(StringRef, bool))
|
|
ERROR(struct_not_fully_initialized,none,
|
|
"struct '%0' must be completely initialized before a member is stored to",
|
|
(StringRef, bool))
|
|
ERROR(immutable_property_already_initialized,none,
|
|
"immutable value '%0' may only be initialized once",
|
|
(StringRef))
|
|
NOTE(initial_value_provided_in_let_decl,none,
|
|
"initial value already provided in 'let' declaration", ())
|
|
ERROR(mutating_method_called_on_immutable_value,none,
|
|
"mutating %select{method|property access|subscript|operator}1 %0 may not"
|
|
" be used on immutable value '%2'",
|
|
(DeclBaseName, unsigned, StringRef))
|
|
ERROR(immutable_value_passed_inout,none,
|
|
"immutable value '%0' must not be passed inout",
|
|
(StringRef))
|
|
ERROR(assignment_to_immutable_value,none,
|
|
"immutable value '%0' must not be assigned to",
|
|
(StringRef))
|
|
ERROR(mutating_protocol_witness_method_on_let_constant,none,
|
|
"cannot perform mutating operation: '%0' is a 'let' constant",
|
|
(StringRef))
|
|
|
|
WARNING(designated_init_in_cross_module_extension,none,
|
|
"initializer for struct %0 must use \"self.init(...)\" or \"self = ...\""
|
|
"%select{| on all paths}1 because "
|
|
"%select{it is not in module %2|the struct was imported from C}3",
|
|
(Type, bool, Identifier, bool))
|
|
NOTE(designated_init_c_struct_fix,none,
|
|
"use \"self.init()\" to initialize the struct with zero values", ())
|
|
|
|
|
|
// Control flow diagnostics.
|
|
ERROR(missing_return,none,
|
|
"missing return in a %select{function|closure}1 expected to return %0",
|
|
(Type, unsigned))
|
|
ERROR(missing_never_call,none,
|
|
"%select{function|closure}1 with uninhabited return type %0 is missing "
|
|
"call to another never-returning function on all paths",
|
|
(Type, unsigned))
|
|
ERROR(guard_body_must_not_fallthrough,none,
|
|
"'guard' body must not fall through, consider using a 'return' or 'throw'"
|
|
" to exit the scope", ())
|
|
WARNING(unreachable_code,none, "will never be executed", ())
|
|
NOTE(unreachable_code_branch,none,
|
|
"condition always evaluates to %select{false|true}0", (bool))
|
|
NOTE(call_to_noreturn_note,none,
|
|
"a call to a never-returning function", ())
|
|
WARNING(unreachable_code_after_stmt,none,
|
|
"code after '%select{return|break|continue|throw}0' will never "
|
|
"be executed", (unsigned))
|
|
WARNING(unreachable_case,none,
|
|
"case will never be executed", ())
|
|
WARNING(switch_on_a_constant,none,
|
|
"switch condition evaluates to a constant", ())
|
|
NOTE(unreachable_code_note,none, "will never be executed", ())
|
|
|
|
// 'transparent' diagnostics
|
|
ERROR(circular_transparent,none,
|
|
"inlining 'transparent' functions forms circular loop", ())
|
|
NOTE(note_while_inlining,none,
|
|
"while inlining here", ())
|
|
|
|
// Arithmetic diagnostics.
|
|
ERROR(integer_conversion_overflow,none,
|
|
"integer overflows when converted from %0 to %1",
|
|
(Type, Type))
|
|
ERROR(integer_conversion_overflow_builtin_types,none,
|
|
"integer overflows when converted from %select{unsigned|signed}0 "
|
|
"%1 to %select{unsigned|signed}2 %3",
|
|
(bool, Type, bool, Type))
|
|
WARNING(integer_conversion_overflow_warn,none,
|
|
"integer overflows when converted from %0 to %1",
|
|
(Type, Type))
|
|
ERROR(integer_conversion_sign_error,none,
|
|
"negative integer cannot be converted to unsigned type %0",
|
|
(Type))
|
|
ERROR(negative_integer_literal_overflow_unsigned,none,
|
|
"negative integer '%1' overflows when stored into unsigned type %0",
|
|
(Type, StringRef))
|
|
|
|
ERROR(integer_literal_overflow,none,
|
|
"integer literal '%1' overflows when stored into %0",
|
|
(Type, StringRef))
|
|
ERROR(integer_literal_overflow_builtin_types,none,
|
|
"integer literal '%2' overflows when stored into "
|
|
"%select{unsigned|signed}0 %1", (bool, Type, StringRef))
|
|
WARNING(integer_literal_overflow_warn,none,
|
|
"integer literal overflows when stored into %0",
|
|
(Type))
|
|
ERROR(arithmetic_operation_overflow,none,
|
|
"arithmetic operation '%0 %1 %2' (on type %3) results in an overflow",
|
|
(StringRef, StringRef, StringRef, Type))
|
|
ERROR(arithmetic_operation_overflow_generic_type,none,
|
|
"arithmetic operation '%0 %1 %2' (on %select{unsigned|signed}3 "
|
|
"%4-bit integer type) results in an overflow",
|
|
(StringRef, StringRef, StringRef, bool, unsigned))
|
|
ERROR(division_overflow,none,
|
|
"division '%0 %1 %2' results in an overflow",
|
|
(StringRef, StringRef, StringRef))
|
|
ERROR(division_by_zero,none, "division by zero", ())
|
|
ERROR(wrong_non_negative_assumption,none,
|
|
"assumed non-negative value '%0' is negative", (StringRef))
|
|
ERROR(shifting_all_significant_bits,none,
|
|
"shift amount is greater than or equal to type size in bits", ())
|
|
|
|
// FIXME: We won't need this as it will be replaced with user-generated strings.
|
|
// staticReport diagnostics.
|
|
ERROR(static_report_error, none,
|
|
"static report error", ())
|
|
|
|
REMARK(opt_remark_passed, none, "%0", (StringRef))
|
|
REMARK(opt_remark_missed, none, "%0", (StringRef))
|
|
|
|
#ifndef DIAG_NO_UNDEF
|
|
# if defined(DIAG)
|
|
# undef DIAG
|
|
# endif
|
|
# undef REMARK
|
|
# undef NOTE
|
|
# undef WARNING
|
|
# undef ERROR
|
|
#endif
|