Skip to content

[TypeChecker] Issue error message when accessing subscript using keyword #5537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/ASTPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class ASTPrinter {
return *this;
}

void printName(Identifier Name,
void printName(DeclName Name,
PrintNameContext Context = PrintNameContext::Normal);

void setIndent(unsigned NumSpaces) {
Expand Down
22 changes: 7 additions & 15 deletions include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,21 +688,16 @@ class ObjCAttr final : public DeclAttribute,
private llvm::TrailingObjects<ObjCAttr, SourceLoc> {
friend TrailingObjects;

/// The Objective-C name associated with this entity, stored in its opaque
/// representation so that we can use null as an indicator for "no name".
void *NameData;
/// The Objective-C name associated with this entity
Optional<ObjCSelector> Name;

/// Create an implicit @objc attribute with the given (optional) name.
explicit ObjCAttr(Optional<ObjCSelector> name, bool implicitName)
: DeclAttribute(DAK_ObjC, SourceLoc(), SourceRange(), /*Implicit=*/true),
NameData(nullptr)
Name(name)
{
ObjCAttrBits.HasTrailingLocationInfo = false;
ObjCAttrBits.ImplicitName = implicitName;

if (name) {
NameData = name->getOpaqueValue();
}
}

/// Create an @objc attribute written in the source.
Expand Down Expand Up @@ -777,14 +772,11 @@ class ObjCAttr final : public DeclAttribute,
bool isNameImplicit);

/// Determine whether this attribute has a name associated with it.
bool hasName() const { return NameData != nullptr; }
bool hasName() const { return Name.hasValue(); }

/// Retrieve the name of this entity, if specified.
Optional<ObjCSelector> getName() const {
if (!hasName())
return None;

return ObjCSelector::getFromOpaqueValue(NameData);
return Name;
}

/// Determine whether the name associated with this attribute was
Expand All @@ -802,13 +794,13 @@ class ObjCAttr final : public DeclAttribute,
ObjCAttrBits.HasTrailingLocationInfo = false;
}

NameData = name.getOpaqueValue();
Name = name;
ObjCAttrBits.ImplicitName = implicit;
}

/// Clear the name of this entity.
void clearName() {
NameData = nullptr;
Name = None;
}

/// Retrieve the source locations for the names in a non-implicit
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/DebuggerClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DebuggerClient {
// in the global context rather than the current context.
// This question will only be asked if the decl's current context
// is a function marked with the LLDBDebuggerFunction attribute.
virtual bool shouldGlobalize(Identifier Name, DeclKind kind) = 0;
virtual bool shouldGlobalize(DeclName Name, DeclKind kind) = 0;

virtual void didGlobalize (Decl *Decl) = 0;

Expand All @@ -48,7 +48,7 @@ class DebuggerClient {
/// be consulted first. Return true if results have been added
/// to RV.
/// FIXME: I don't think this ever does anything useful.
virtual bool lookupOverrides(Identifier Name, DeclContext *DC,
virtual bool lookupOverrides(DeclName Name, DeclContext *DC,
SourceLoc Loc, bool IsTypeLookup,
ResultVector &RV) = 0;

Expand All @@ -57,7 +57,7 @@ class DebuggerClient {
/// gets a chance to add names to the list of candidates that
/// have been found in the external module lookup.

virtual bool lookupAdditions(Identifier Name, DeclContext *DC,
virtual bool lookupAdditions(DeclName Name, DeclContext *DC,
SourceLoc Loc, bool IsTypeLookup,
ResultVector &RV) = 0;

Expand Down
23 changes: 18 additions & 5 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1965,13 +1965,12 @@ class ValueDecl : public Decl {
}

bool hasName() const { return bool(Name); }
/// TODO: Rename to getSimpleName?
Identifier getName() const { return Name.getBaseName(); }

bool isOperator() const { return Name.isOperator(); }

/// Returns the string for the base name, or "_" if this is unnamed.
StringRef getNameStr() const {
return hasName() ? getName().str() : "_";
return hasName() ? getBaseName().str() : "_";
}

/// Retrieve the full name of the declaration.
Expand Down Expand Up @@ -2186,6 +2185,10 @@ class TypeDecl : public ValueDecl {
}

public:
Identifier getIdentifier() const {
return getBaseName().getIdentifier();
}

/// The type of this declaration's values. For the type of the
/// declaration itself, use getInterfaceType(), which returns a
/// metatype.
Expand Down Expand Up @@ -4051,7 +4054,7 @@ class VarDecl : public AbstractStorageDecl {
llvm::PointerUnion<PatternBindingDecl*, Stmt*> ParentPattern;

VarDecl(DeclKind Kind, bool IsStatic, bool IsLet, SourceLoc NameLoc,
Identifier Name, Type Ty, DeclContext *DC)
DeclName Name, Type Ty, DeclContext *DC)
: AbstractStorageDecl(Kind, DC, Name, NameLoc)
{
VarDeclBits.IsUserAccessible = true;
Expand All @@ -4068,7 +4071,7 @@ class VarDecl : public AbstractStorageDecl {
Type typeInContext;

public:
VarDecl(bool IsStatic, bool IsLet, SourceLoc NameLoc, Identifier Name,
VarDecl(bool IsStatic, bool IsLet, SourceLoc NameLoc, DeclName Name,
Type Ty, DeclContext *DC)
: VarDecl(DeclKind::Var, IsStatic, IsLet, NameLoc, Name, Ty, DC) { }

Expand Down Expand Up @@ -4255,6 +4258,12 @@ class ParamDecl : public VarDecl {
/// accidental copies.
ParamDecl(ParamDecl *PD);

/// Retrieve the identifier for the name of this parameter
Identifier getIdentifier() const {
// ParamDecls can't carry a special DeclName
return getBaseName().getIdentifier();
}

/// Retrieve the argument (API) name for this function parameter.
Identifier getArgumentName() const { return ArgumentName; }

Expand Down Expand Up @@ -5197,6 +5206,10 @@ class EnumElementDecl : public ValueDecl {
EnumElementDeclBits.Recursiveness =
static_cast<unsigned>(ElementRecursiveness::NotRecursive);
}

Identifier getIdentifier() {
return getBaseName().getIdentifier();
}

/// \returns false if there was an error during the computation rendering the
/// EnumElementDecl invalid, true otherwise.
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsCommon.def
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ERROR(error_no_group_info,none,

NOTE(previous_decldef,none,
"previous %select{declaration|definition}0 of %1 is here",
(bool, Identifier))
(bool, DeclName))


// Generic disambiguation
Expand Down
12 changes: 6 additions & 6 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ ERROR(lex_conflict_marker_in_file,none,
//------------------------------------------------------------------------------

NOTE(note_in_decl_extension,none,
"in %select{declaration|extension}0 of %1", (bool, Identifier))
"in %select{declaration|extension}0 of %1", (bool, DeclName))
ERROR(line_directive_style_deprecated,none,
"#line directive was renamed to #sourceLocation",
())
Expand Down Expand Up @@ -551,9 +551,9 @@ ERROR(multiple_sil_stage_decls, none,
ERROR(expected_sil_vtable_colon,none,
"expected ':' in a vtable entry", ())
ERROR(sil_vtable_func_not_found,none,
"sil function not found %0", (Identifier))
"sil function not found %0", (DeclName))
ERROR(sil_vtable_class_not_found,none,
"sil class not found %0", (Identifier))
"sil class not found %0", (DeclName))

// SIL Global
ERROR(sil_global_variable_not_found,none,
Expand All @@ -567,7 +567,7 @@ ERROR(expected_sil_witness_lparen,none,
ERROR(expected_sil_witness_rparen,none,
"expected ')' in a witness table", ())
ERROR(sil_witness_func_not_found,none,
"sil function not found %0", (Identifier))
"sil function not found %0", (DeclName))
ERROR(sil_witness_protocol_not_found,none,
"sil protocol not found %0", (Identifier))
ERROR(sil_witness_assoc_not_found,none,
Expand All @@ -577,7 +577,7 @@ ERROR(sil_witness_protocol_conformance_not_found,none,

// SIL Coverage Map
ERROR(sil_coverage_func_not_found, none,
"sil function not found %0", (Identifier))
"sil function not found %0", (DeclName))
ERROR(sil_coverage_invalid_hash, none,
"expected coverage hash", ())
ERROR(sil_coverage_expected_lbrace, none,
Expand Down Expand Up @@ -722,7 +722,7 @@ ERROR(var_pattern_in_var,none,
"'%select{var|let}0' cannot appear nested inside another 'var' or "
"'let' pattern", (unsigned))
ERROR(extra_var_in_multiple_pattern_list,none,
"%0 must be bound in every pattern", (Identifier))
"%0 must be bound in every pattern", (DeclName))
ERROR(let_pattern_in_immutable_context,none,
"'let' pattern cannot appear nested in an already immutable context", ())
ERROR(inout_must_have_type,none,
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ERROR(could_not_find_pointer_pointee_property,none,

ERROR(writeback_overlap_property,none,
"inout writeback to computed property %0 occurs in multiple arguments to"
" call, introducing invalid aliasing", (Identifier))
" call, introducing invalid aliasing", (DeclName))
ERROR(writeback_overlap_subscript,none,
"inout writeback through subscript occurs in multiple arguments to call,"
" introducing invalid aliasing",
Expand Down Expand Up @@ -120,7 +120,7 @@ ERROR(self_use_before_fully_init,none,
"use of 'self' in %select{method call|property access}1 %0 before "
"%select{all stored properties are initialized|"
"super.init initializes self|"
"self.init initializes self}2", (Identifier, bool, unsigned))
"self.init initializes self}2", (DeclName, bool, unsigned))
ERROR(use_of_self_before_fully_init,none,
"'self' used before all stored properties are initialized", ())
ERROR(use_of_self_before_fully_init_protocol,none,
Expand Down Expand Up @@ -166,7 +166,7 @@ NOTE(initial_value_provided_in_let_decl,none,
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'",
(Identifier, unsigned, StringRef))
(DeclName, unsigned, StringRef))
ERROR(immutable_value_passed_inout,none,
"immutable value '%0' may not be passed inout",
(StringRef))
Expand Down
Loading