Suggestion for a more useful error message for template field duplication

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.

1 Like

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.

5 Likes

Thank you!

1 Like

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.

3 Likes

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.

1 Like

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.

3 Likes

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:

2 Likes