Skip to content

[interface-gen] Avoid double-printing mutating #30183

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 1 commit 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
4 changes: 3 additions & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2846,7 +2846,9 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) {
if (!Options.SkipIntroducerKeywords) {
if (decl->isStatic() && Options.PrintStaticKeyword)
printStaticKeyword(decl->getCorrectStaticSpelling());
if (decl->isMutating() && !Options.excludeAttrKind(DAK_Mutating)) {
if (decl->isMutating() &&
!decl->getAttrs().hasAttribute<MutatingAttr>() &&
!Options.excludeAttrKind(DAK_Mutating)) {
Printer.printKeyword("mutating", Options, " ");
} else if (decl->isConsuming() && !decl->getAttrs().hasAttribute<ConsumingAttr>()) {
Printer.printKeyword("__consuming", Options, " ");
Expand Down
8 changes: 8 additions & 0 deletions test/SourceKit/InterfaceGen/Inputs/Foo3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ public class C {
}
}
}

public struct MyStruct {
public mutating func mutatingFunc() {}
public var mutVar: Int {
mutating get { 1 }
nonmutating set {}
}
}
8 changes: 8 additions & 0 deletions test/SourceKit/InterfaceGen/Inputs/swift_mod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ public func pub_function() {}
internal func int_function() {}
fileprivate func fp_function() {}
private func priv_function() {}

public struct MyStruct {
public mutating func mutatingFunc() {}
public var mutVar: Int {
mutating get { 1 }
nonmutating set {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ public class MyClass {
public func pub_method()
}

public struct MyStruct {

public mutating func mutatingFunc()

public var mutVar: Int { mutating get nonmutating set }
}

public func pub_function()


Expand Down Expand Up @@ -46,15 +53,97 @@ public func pub_function()
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 64,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 71,
key.length: 8
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 87,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 94,
key.length: 8
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 103,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 69,
key.offset: 108,
key.length: 12
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 128,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 135,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 139,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.typeidentifier,
key.offset: 147,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 153,
key.length: 8
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 162,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 166,
key.length: 11
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 178,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.attribute.builtin,
key.offset: 187,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 194,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 199,
key.length: 12
}
]
[
{
key.kind: source.lang.swift.ref.struct,
key.offset: 147,
key.length: 3,
key.is_system: 1
}
]
<<NULL>>
[
{
key.kind: source.lang.swift.decl.class,
Expand Down Expand Up @@ -92,17 +181,77 @@ public func pub_function()
}
]
},
{
key.kind: source.lang.swift.decl.struct,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "MyStruct",
key.offset: 64,
key.length: 121,
key.nameoffset: 71,
key.namelength: 8,
key.bodyoffset: 81,
key.bodylength: 103,
key.attributes: [
{
key.offset: 57,
key.length: 6,
key.attribute: source.decl.attribute.public
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "mutatingFunc()",
key.offset: 103,
key.length: 19,
key.nameoffset: 108,
key.namelength: 14,
key.attributes: [
{
key.offset: 94,
key.length: 8,
key.attribute: source.decl.attribute.mutating
},
{
key.offset: 87,
key.length: 6,
key.attribute: source.decl.attribute.public
}
]
},
{
key.kind: source.lang.swift.decl.var.instance,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "mutVar",
key.offset: 135,
key.length: 48,
key.typename: "Int",
key.nameoffset: 139,
key.namelength: 6,
key.bodyoffset: 152,
key.bodylength: 30,
key.attributes: [
{
key.offset: 128,
key.length: 6,
key.attribute: source.decl.attribute.public
}
]
}
]
},
{
key.kind: source.lang.swift.decl.function.free,
key.accessibility: source.lang.swift.accessibility.public,
key.name: "pub_function()",
key.offset: 64,
key.offset: 194,
key.length: 19,
key.nameoffset: 69,
key.nameoffset: 199,
key.namelength: 14,
key.attributes: [
{
key.offset: 57,
key.offset: 187,
key.length: 6,
key.attribute: source.decl.attribute.public
}
Expand Down
Loading