2

Compile Error

I cannot understand why this happens.I copied and pasted this code from https://zoom-blc.com/how-to-create-first-dapp

Error message is as follows:

truffle(develop)> compile
Error parsing /Users/akitasatoshi/pet-shop-tutorial/contracts/Adoption.sol: ParsedContract.sol:10:3: ParserError: Expected primary expression.
    return petId;
  ^

The code is as follows:

pragma solidity ^0.4.23;

contract Adoption {

  address[16] public adopters;

  function adopt(uint petId) returns(uint) { 
    require(petId >= 0 && petId =< 15);
    adopters [pedId] = msg.sender;
    return petId;
  }

  function getAdopters(uint) public returns (address[16]) {
    return adopters;
  }
1

A few things:

  • There's no closing brace on your contract.
  • There's a space in the line adopters [pedId].
  • There's a typo in the same line. pedId -> petId.

The actual issue you've reported is due to =<, which should be <=.


Edit:

I copied and pasted this code from...

Okay, I tried copy+pasting from that site, and Remix didn't like it. There seem to be some special characters at the beginning of each line that are causing problems, specifically U+3000, which is the "Ideographic Space" character. Might be related to it being a Japanese site? Don't know.

Removing any whitespace from the beginning of each line, then re-indenting using a "normal" space/tab gets things working.

1
  • Firstly, sorry for lots of typos.. Thank you! I could compile them. I did not notice the "Ideographic Space", so wondered error which indicating blank.
    – Ryo Akita
    Oct 10 '18 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.