<commit_before>//===--- TypeCheckAttr.cpp - Type Checking for Attributes -----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements semantic analysis for attributes.
//
//===----------------------------------------------------------------------===//

#include "TypeChecker.h"
#include "swift/AST/ASTVisitor.h"
using namespace swift;

namespace {
  class AttributeChecker : public AttributeVisitor<AttributeChecker> {
    TypeChecker &TC;
    Decl *D;
  public:
    AttributeChecker(TypeChecker &TC, Decl *D) : TC(TC), D(D) {}

    /// Deleting this ensures that all attributes are covered by the visitor
    /// below.
    void visitDeclAttribute(DeclAttribute *A) = delete;

    void visitAsmnameAttr(AsmnameAttr *attr) { }

    
    void visitAvailabilityAttr(AvailabilityAttr *attr) {
      // FIXME: Check that this declaration is at least as available as the
      // one it overrides.
    }
    
    void visitFinalAttr(FinalAttr *attr);
    
    void visitObjCAttr(ObjCAttr *attr) {
    }
    
  };
} // end anonymous namespace




void AttributeChecker::visitFinalAttr(FinalAttr *attr) {
  // FIXME: Customize message to the kind of thing.
  //      TC.diagnose(Override, diag::override_final);
  //      TC.diagnose(Base, diag::overridden_here);
  
  auto typeContext = D->getDeclContext()->getDeclaredTypeInContext();
  auto contextTypeDecl =
    typeContext ? typeContext->getNominalOrBoundGenericNominal() : nullptr;
  if (!isa<ClassDecl>(contextTypeDecl))
    TC.diagnose(D, diag::member_cannot_be_final);
 
}



<commit_msg>correctly reject @final on global functions instead of crashing.<commit_after>//===--- TypeCheckAttr.cpp - Type Checking for Attributes -----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements semantic analysis for attributes.
//
//===----------------------------------------------------------------------===//

#include "TypeChecker.h"
#include "swift/AST/ASTVisitor.h"
using namespace swift;

namespace {
  class AttributeChecker : public AttributeVisitor<AttributeChecker> {
    TypeChecker &TC;
    Decl *D;
  public:
    AttributeChecker(TypeChecker &TC, Decl *D) : TC(TC), D(D) {}

    /// Deleting this ensures that all attributes are covered by the visitor
    /// below.
    void visitDeclAttribute(DeclAttribute *A) = delete;

    void visitAsmnameAttr(AsmnameAttr *attr) { }

    
    void visitAvailabilityAttr(AvailabilityAttr *attr) {
      // FIXME: Check that this declaration is at least as available as the
      // one it overrides.
    }
    
    void visitFinalAttr(FinalAttr *attr);
    
    void visitObjCAttr(ObjCAttr *attr) {
    }
    
  };
} // end anonymous namespace




void AttributeChecker::visitFinalAttr(FinalAttr *attr) {
  // FIXME: Customize message to the kind of thing.
  //      TC.diagnose(Override, diag::override_final);
  //      TC.diagnose(Base, diag::overridden_here);
  
  
  // The @final attribute only makes sense in the context of a
  auto typeContext = D->getDeclContext()->getDeclaredTypeInContext();
  auto contextTypeDecl =
    typeContext ? typeContext->getNominalOrBoundGenericNominal() : nullptr;
  if (!contextTypeDecl || !isa<ClassDecl>(contextTypeDecl)) {
    TC.diagnose(D, diag::member_cannot_be_final);
    return;
  }
 
  
  
  
}




{'fraction_non_alphanumeric': 0.1858817782120176, 'fraction_numerical': 0.004885197850512946, 'mean_word_length': 2.4096586178184847, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6929034', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1104, 'n_words': 329}