digital-asset / daml

The Daml smart contract language
https://www.digitalasset.com/developers
Other
802 stars 204 forks source link

Misleading error message about cyclic module dependencies #7181

Open aherrmann-da opened 4 years ago

aherrmann-da commented 4 years ago

A wrong module name due to a missing hierarchical prefix can lead to a misleading error message about cyclic module dependencies. The issue can be reproduced as follows:

daml/Main.daml

module Main where

daml/Test/Main.daml

module Test.Main where
import Main
import Test.Helper

daml/Test/Helper.daml

-- Wrong module name, should be 'Test.Helper'
module Helper where
import Main

Leads to the following error message about cyclic module dependencies, when in fact the issue is a wrong module name.

$ daml build
Compiling repro to a DAR.
File:     daml/Test/Helper.daml
Hidden:   no
Range:    3:7-3:11
Source:   Import cycle detection
Severity: DsError
Message:  Cyclic module dependency between Helper, Test.Main
File:     daml/Test/Main.daml
Hidden:   no
Range:    3:7-3:18
Source:   Import cycle detection
Severity: DsError
Message:  Cyclic module dependency between Helper, Test.Main
ERROR: Creation of DAR file failed.

This was encountered on DAML SDK HEAD as of a080b47e347277e099167fc59affde9dac313342.

sofiafaro-da commented 4 years ago

Based on my reading of the "bad module name" code, it isn't currently an error that the Helper module is named Helper instead of Test.Helper. Suffixes of full module paths are apparently allowed. This should probably be fixed.

On the other hand, it is also strange that a cyclic dependency is detected, but if you take out the import Main from Helper.daml you get a very different error:

File:     daml/Test/Main.daml
Hidden:   no
Range:    3:0-3:18
Source:   typecheck
Severity: DsError
Message: 
  daml/Test/Main.daml:3:1: error:
  Could not find module ‘Test.Helper’
  It is not a module in the current program, or in any known package.

So, damlc, which error are you really seeing? Is it a cyclic dependency or a missing module? It's contradictory.