Ethereum Pet Shop tutorial - ParserError: Expected pragma, import directive or contract/interface/library definition

Ethereum Pet Shop tutorial - ParserError: Expected pragma, import directive or contract/interface/library definition

我正在尝试按照教程 here 学习如何编写 dapp。我把这个 .sol 代码放在一起(好吧,copy/pasted...):

pragma solidity ^0.5.0;

contract Adoption {
address[16] public adopters;
}

// Adopting a pet
function adopt(uint petId) public returns (uint) {
  require(petId >= 0 && petId <= 15);

  adopters[petId] = msg.sender;

  return petId;
}

// Retrieving the adopters
function getAdopters() public view returns (address[16] memory) {
  return adopters;
}

并且已经有另一个文件。当我 运行 truffle 编译命令时,我看到以下内容:

ParserError: Expected pragma, import directive or contract/interface/library definition.
function adopt(uint petId) public returns (uint) {
^------^

Compilation failed. See above.
Truffle v5.1.34 (core: 5.1.34)
Node v12.18.2

知道我可能遗漏了什么吗?

函数必须在 contract 范围内:

pragma solidity ^0.5.0;

contract Adoption {
  address[16] public adopters;


  // Adopting a pet
  function adopt(uint petId) public returns (uint) {
    require(petId >= 0 && petId <= 15);

    adopters[petId] = msg.sender;

    return petId;
  }

  // Retrieving the adopters
  function getAdopters() public view returns (address[16] memory) {
    return adopters;
  }

} // <= closing brace