Skip to content

Fix: Detect cycles in `#include` paths and give proper error message

Melwyn Saldanha requested to merge fix/include_cycle into dev

Motivation and Context

In case of cyclic #includes we get a Stack overflow error,

It would be nice to detect this case and present a nice error message, showing files which cause the cycle.

Description

This MR maintains a list of ancestors while preprocessing #include, and checks if current file is present in the list of ancestors and fails with an error if the file is present.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Performance improvement (non-breaking change that improves performance)
  • None (change with no changelog)

Changelog

Before:

$ ligo.54 print preprocessed x.mligo 
An internal error ocurred. Please, contact the developers.
("Stack overflow").

After

$ ligo print preprocessed x.mligo 
File "x.mligo", line 1, characters 9-18:
  1 | #include "y.mligo"
  2 | 
Error: Dependency cycle between:
-> "x.mligo"
-> "y.mligo"

Checklist:

  • Changes follow the existing coding style (use dune @fmt to check).
  • Tests for the changes have been added (for bug fixes / feature).
  • Documentation has been updated.
  • Changelog description has been added (if appropriate).
  • Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Melwyn Saldanha

Merge request reports

Loading