Skip to content
Merged
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
3 changes: 3 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8418,6 +8418,9 @@ class MacroDecl : public GenericContext, public ValueDecl {
/// Retrieve the definition of this macro.
MacroDefinition getDefinition() const;

/// Retrieve the parameter list of this macro.
ParameterList *getParameterList() const { return parameterList; }

/// Retrieve the builtin macro kind for this macro, or \c None if it is a
/// user-defined macro with no special semantics.
Optional<BuiltinMacroKind> getBuiltinKind() const;
Expand Down
5 changes: 4 additions & 1 deletion lib/Sema/TypeCheckAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,6 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
UNINTERESTING(Destructor) // Always correct.
UNINTERESTING(Accessor) // Handled by the Var or Subscript.
UNINTERESTING(OpaqueType) // Handled by the Var or Subscript.
UNINTERESTING(Macro)

/// If \p VD's layout is exposed by a @frozen struct or class, return said
/// struct or class.
Expand Down Expand Up @@ -1569,6 +1568,10 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
}
}

void visitMacroDecl(MacroDecl *MD) {
// FIXME: Check access of macro generic parameters, parameters and result
}

void visitEnumElementDecl(EnumElementDecl *EED) {
if (!EED->hasAssociatedValues())
return;
Expand Down
2 changes: 2 additions & 0 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
if (!MD->getAttrs().hasAttribute<MacroRoleAttr>(/*AllowInvalid*/ true))
MD->diagnose(diag::macro_without_role, MD->getName());

TypeChecker::checkParameterList(MD->getParameterList(), MD);

// Check the macro definition.
switch (auto macroDef = MD->getDefinition()) {
case MacroDefinition::Kind::Undefined:
Expand Down
7 changes: 7 additions & 0 deletions test/Serialization/Inputs/def_macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ public struct Base {
public struct TestMacroArgTypechecking {
public var value: Int
}

@resultBuilder
public struct Builder {
static func buildBlock(_: Int...) -> Void {}
}
@freestanding(expression)
public macro macroWithBuilderArgs(@Builder _: () -> Void) = #externalMacro(module: "A", type: "B")
8 changes: 8 additions & 0 deletions test/Serialization/macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// RUN: %target-build-swift -I %swift-host-lib-dir -L %swift-host-lib-dir -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/def_macro_plugin.swift -g -no-toolchain-stdlib-rpath
// RUN: %target-swift-frontend -emit-module -o %t/def_macros.swiftmodule %S/Inputs/def_macros.swift -module-name def_macros -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir
// RUN: %target-swift-frontend -typecheck -I%t -verify %s -verify-ignore-unknown -enable-experimental-feature Macros -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir
// RUN: llvm-bcanalyzer %t/def_macros.swiftmodule | %FileCheck %s
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-module -module-to-print=def_macros -I %t -source-filename=%s | %FileCheck -check-prefix=CHECK-PRINT %s
// REQUIRES: OS=macosx

import def_macros
Expand All @@ -19,3 +21,9 @@ func test(a: Int, b: Int) {
struct TestStruct {
@myWrapper var x: Int
}

// CHECK: MACRO_DECL

// CHECK-NOT: UnknownCode

// CHECK-PRINT-DAG: macro macroWithBuilderArgs(@Builder _: () -> Void)