Skip to content
Discussions/App Development/Suggestion for a more useful error message for template field duplicationForum ↗

Suggestion for a more useful error message for template field duplication

App Development7 posts366 views16 likesLast activity Mar 2021
GY
gyorgybalazsiOP
Mar 2021

I have noticed that when I duplicate a field in a contract template, I get an error message, but it doesn’t highlight the source of the problem.

Could we fix that somehow?

In the example below, the problem is that I duplicated the owner field of the Asset template, but this isn’t highlighted.

CO
cocreature
Mar 2021

This looks like a side effect of the following being valid Haskell program:

{-# LANGUAGE DuplicateRecordFields, DisambiguateRecordFields #-}
module Test where

data X = X { a :: Int, a :: Int }

I don’t actually know why this is valid. DuplicateRecordFields is supposed to allow for duplicate fields in different records, I don’t see why it’s valid within the same record.

The case that blows up in your example is then not the definition of the datatype but one of the generated methods for things like choices, signatories, … which is why the l ocation is off.

We could probably add our own check here. I opened Better errors on duplicate record fields · Issue #8994 · digital-asset/daml · GitHub to track this.

GY
gyorgybalazsi
Mar 2021

Thank you!

CO
cocreature
Mar 2021

We just merged an improvement here. The following template

template T
  with
    a : Int
    a : Bool
    p : Party
  where
    signatory p

now produces the error:

File:     daml/Main.daml
Hidden:   no
Range:    8:5-8:6
Source:   parser
Severity: DsError
Message:  Duplicate field name a. Original definition at daml/Main.daml:7:5.

which highlights the duplicate field and shows you the location of the first field definition.

GY
gyorgybalazsi
Mar 2021

Thank you, does it also highlight the error when the fields with identical names have the same type? Actually this was the case when I encountered the error, I copy+pasted the list of fields from another template, and there was an overlap so I copied the field twice.

GA
Gary_Verhaegen
Mar 2021

To set expectations, it’s worth mentioning that, as this just missed the 1.11 RC train, this improvement will not be included in the stable Daml Connect 1.11 release, but will (likely) be included in the first snapshot of the 1.12 development cycle, which should be created around the second half of next week.

CO
cocreature
Mar 2021

We always highlight the location of the error. In the example above 8:5-8:6 is the second occurence of a. Here is a screenshot, to better demonstrate it:

← Back to Discussions