Parse error on input do

Hello there! I’m trying to create a simple auction contract with daml to show to my professor. I managed to create something following the template of another contract that I’ve already created successfully. However, in the auction contract at some point it displays the message “Parse error on input 2” and I don’t know what I did wrong. Thank you in advance to those who will be able to help!



Daml is a space sensitive language.

It is hard to know precisely but can you try aligning the choice names, ie the D in “Decline” with the M in “MakeANewBild” ? And the w in “with” with the d in “do” ?

1 Like

If you could, please include copy-pasted Daml code text that yields the error instead of screenshots; the forum will format Daml code nicely if you put it between ``` lines,

module LikeSo

template Foo with -- ...
-- more code

But my guess is the same as @Leonid_Rozenberg 's, i.e. Decline needs to be lined up with the previous choice name.

I tried that and if I align the d of decline with the m of MakeANewBid it displays even more errors. While if I align the d of do with the w of with nothing changes.


template Auction 
   with
      auctioneer: Party
      bidder: Party
      object: Text
      bid: Decimal
      limit: Decimal
      currency: Text
      start: Time
      end: Time
      dateAuction: Date
    where 
      signatory auctioneer , bidder 
      ensure limit > 0 && start < end

template AuctionBid
   with 
       auctioneer: Party
       bidder: Party
       object: Text
       bid: Decimal
       currency: Text
       limit: Decimal
       start: Time
       end: Time
    where 
       signatory auctioneer 
       
       controller bidder can 
          MakeABid: ContractId Bid 
            with 
                limit: Decimal
                start: Time
                end: Time
                bid: Decimal
                currency: Text
           do 
            create Bid 
                with 
                  limit = > 10.0
                  start = 10.30
                  end = 11.00
                  bid= 1000.00
                  currency = "Pound"
                  
            Decline: ContractId DeclineBid
                 with
                    reason: Text
                 do 
                    create DeclineBid 
                       with
                        ..
                       
                        
                
template DeclineBid
   with
       auctioneer: Party
       bidder: Party
       object: Text
       bid: Decimal
       currency: Text
       limit: Decimal
       start: Time
       end: Time
       reason: Text
    where 
       signatory auctioneer , bidder 

       controller bidder can
          MakeANewBid: ContractId AuctionBid 
            do 
              create AuctionBid with ..

Nevertheless, those errors are positive progress in your development. What is happening is that the rule about the alignment of the choices is checked earlier; those errors don’t go away, they were simply hidden by the earlier alignment check failing. As a rule, fewer errors doesn’t definitely mean you’re closer to working code; though it often works out that way, it doesn’t in this case. A better rule of thumb is that more complicated errors means you’re closer to working code; simple syntax errors prevent semantics from being checked and reported on.

If you’re seeing the “Conflicting definitions” error, that’s telling you that you’re defining two bid variables in the same scope, two limit variables, and so on, and that’s probably a mistake. You’ve already defined those as part of the contract payload (under template... with); did you mean to move them?

Deleting those variables from the choice arguments fixes that error and the remaining errors in what you’ve posted; I’ve also passed through the contract payload variables under the assumption that this is what you actually want. (If it’s not, use different variable names.) Changes to your code shown in this diff patch (via - and + lines):

--- daml/ForumTest.orig.daml	2021-10-26 18:07:48.000000000 -0400
+++ daml/ForumTest.daml	2021-10-26 18:08:03.000000000 -0400
@@ -13,7 +13,7 @@
       dateAuction: Date
     where 
       signatory auctioneer , bidder 
-      ensure limit > 0 && start < end
+      ensure limit > 0.0 && start < end
 
 template AuctionBid
    with 
@@ -31,21 +31,15 @@
        controller bidder can 
           MakeABid: ContractId Bid 
             with 
-                limit: Decimal
-                start: Time
-                end: Time
-                bid: Decimal
-                currency: Text
-           do 
-            create Bid 
-                with 
-                  limit = > 10.0
-                  start = 10.30
-                  end = 11.00
-                  bid= 1000.00
-                  currency = "Pound"
-                  
-            Decline: ContractId DeclineBid
+            do 
+              create Bid with 
+                  limit
+                  start
+                  end
+                  bid
+                  currency
+
+          Decline: ContractId DeclineBid
                  with
                     reason: Text
                  do 
@@ -73,3 +67,13 @@
           MakeANewBid: ContractId AuctionBid 
             do 
               create AuctionBid with ..
+
+-- just a sample, wasn't included
+template Bid with
+    limit: Decimal
+    start: Time
+    end: Time
+    bid: Decimal
+    currency: Text
+  where
+    signatory [] -- error, contracts need signatories
1 Like

First of all, thank you so much for trying to help me, I really appreciate that. I tried to create another page to redo all the contract from the beginning trying to respect the spaces and the overall setting. However now it says that there are conflicting definitions for:
limit = > 10.0

  •              start = 10.30
    
  •              end = 11.00
    
  •              bid= 1000.00
    
  •              currency = "Pound"
    

If I try to delete them, the error stays. How do you think I should edit that part?

module Auction2 where 


template Auction2
  with 
    auctioneer : Party  
    bidder : Party 
    object: Text
    bid: Decimal
    limit: Decimal 
    currency: Text 
    start: Time
    end: Time
    dateAuction: Date 
  where
     signatory auctioneer, bidder 
     ensure limit > 0 && start < end

template AuctionBid
   with 
      auctioneer: Party
      bidder: Party
      object: Text
      bid: Decimal
      currency: Text
      limit: Decimal
      start: Time
      end: Time
    where 
       signatory auctioneer 

       controller bidder can 
          MakeABid: ContractId Auction2 
             with
                limit: Decimal 
                start: Time
                end: Time
                bid: Decimal
                currency: Text
            do
              create Auction2
                 with
                    limit = > 10.0
                    start = 10.30
                    end = 11.00
                    bid= 1000.00
                    currency = "Pound"
                
                    
          Decline: ContractId DeclineBid 
            with 
              reason: Text 
              
            do 
              create DeclineBid with ..

template DeclineBid
   with 
      auctioneer: Party
      bidder: Party
      object: Text
      bid: Decimal
      currency: Text
      limit: Decimal
      start: Time
      end: Time
      reason: Text 
    where 
       signatory auctioneer, bidder 

       controller bidder can 
          MakeNewBid: ContractId AuctionBid
            do 
              create AuctionBid with ..

The issue is that your choice defines fields with the same name as the template fields. The easiest fix is to rename one of them, e.g., suffix the fields in the choice argument

       controller bidder can
          MakeABid: ContractId Auction2
             with
                limitArg: Decimal
                startArg: Time
                endArg: Time
                bidArg: Decimal
                currencyArg: Text
            do
              create Auction2
                 with
                    limit = > 10.0
                    start = 10.30
                    end = 11.00
                    bid= 1000.00
                    currency = "Pound"

Once you fixed that, you’ll get another error about limit = > 10.0. I assume that’s probably just a typo and you meant limit = 10.0.

After fixing that there is another error at ensure limit > 0. That is caused by the fact that 0 is of type Int whereas limit is of type Decimal. You can use ensure limit > 0.0 instead to fix that.

On to the next error

  daml/Main.daml:40:22: error:
  • Constructor ‘Auction2’ does not have the required strict field(s): auctioneer,
  bidder, object, dateAuction

You didn’t specify all fields here when calling create Action2. The first 3 can be copied from Auction2 either by specifying them manually or by using .. which copies the fields of the given name that are already in scope. I don’t know what you want to set dateAuction to. In the interest of fixing the error so we can take a look at later errors, let’s set it to the current date. Note that you need to import DA.Date` for this to work.

              currentTime <- getTime
              create Auction2
                 with
                    limit = 10.0
                    start = 10.30
                    end = 11.00
                    bid= 1000.00
                    currency = "Pound"
                    auctioneer = auctioneer
                    bidder = bidder
                    object = object
                    dateAuction = toDateUTC currentTime

And on to the next error:

  • No instance for (IsNumeric Time) arising from the literal ‘10.30’

This comes from start = 10.30. 10.30 is a numeric value but you need a time here. You could specify a time using the functions from DA.Time. However, I think there might actually be another issue here: Your choice defines a number of arguments including start or startArg. However you are not actually using them anywhere. I’m also not sure about the relationship between the fields in the choice argument and the fields in the template. If they are always idenical you don’t need the choice argument. Let’s assume for now that they are not but make sure that we actually use the choice arguments instead of setting the fields to fixed values (however I do recommend understanding how the two relate, I wouldn’t be surprised if you can just delete them from the choice arguments):

create Auction2
                 with
                    limit = limitArg
                    start = startArg
                    end = endArg
                    bid= bidArg
                    currency = currencyArg
                    auctioneer = auctioneer
                    bidder = bidder
                    object = object
                    dateAuction = toDateUTC currentTime

And at that point we’ve resolved all compile errors!

1 Like

Thanks so much! This was very helpful :slight_smile: ! However, it displays an error for “toDateUTC”. It says:

	"resource": "/Users/alicericcardi/auction-contract/daml/Auction.daml",
	"owner": "_generated_diagnostic_collection_name_#0",
	"severity": 8,
	"message": "/Users/alicericcardi/auction-contract/daml/Auction.daml:51:35: error:\n    Variable not in scope: toDateUTC : Time -> Date",
	"source": "typecheck",
	"startLineNumber": 51,
	"startColumn": 35,
	"endLineNumber": 51,
	"endColumn": 44
}
Also I have another error in the part after that. For "Decline" it says that there and indentation or brackets error, but I really don't understand what I should change because I think the indentation is correct and there are no brackets. I'll copy that part here and maybe you know what I should change. (I'm sorry for bothering again, but I have to hand in this auction contract to my professor on the 29th)
`````controller bidder can
          MakeABid: ContractId Auction
             with
                limitArg: Decimal
                startArg: Time
                endArg: Time
                bidArg: Decimal
                currencyArg: Text
            do
              currentTime <- getTime
              create Auction
                 with
                    limit = limitArg
                    start = startArg
                    end = endArg
                    bid= bidArg
                    currency = currencyArg
                    auctioneer = auctioneer
                    bidder = bidder
                    object = object
                    dateAuction = toDateUTC currentTime

                    
                  
          Decline: ContractId DeclineBid 
             with 
                reason: Text 
             do 
              create DeclineBid with ..

The error about toDateUTC is due to a missing import. As I suggested above, you need to import DA.Date. To do so add

import DA.Date

after the module Auction2 where line.

As for the other error you are mentioning, I think you have to share your full example. Beyond the fact that you renamed Auction2 back to Auction that code seems to work fine.

For reference this is the full working version that I hacked up Auction2.daml · GitHub

1 Like

Sorry for changing between Auction and Auction2, but I opened two work files so that I can try different things and see what works and what doesn’t. Also, the moment I imported DA.Date even the error on Decline disappeared :slight_smile:
Thank you very much and I hope my professor likes this auction contract!

1 Like