Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anonymous top module confuses Agda #1388

Closed
GoogleCodeExporter opened this issue Aug 8, 2015 · 5 comments
Closed

Anonymous top module confuses Agda #1388

GoogleCodeExporter opened this issue Aug 8, 2015 · 5 comments
Labels
modules Issues relating to the module system parser Problems with the parser's implementation (rather than with decisions about syntax) regression on master Unreleased regression in development version (Change to "regression in ..." should it be released!) type: bug Issues and pull requests about actual bugs
Milestone

Comments

@GoogleCodeExporter
Copy link

As expected, true is not in scope when trying to bind it to 'test':

module _ where

open import Common.Equality

module _ where
  open import Common.Prelude

test = true  -- fails as expected

However, if I delete the top-level anonymous module header, it is:

open import Common.Equality

module _ where
  open import Common.Prelude

test = true  -- works, but should fail

I would expect a parse error, as first stuff is indented, and then not.
However, it seems to be legal Agda:

module IndentationInTopModule where

  indented = Set

not-indented = Set

  -- again-indented = Set  -- Parse error

This parses: you can indent in the top module, then unindent. But if you
indent again, you get a parse error!?

Note that this is not allowed in inner modules!

module InnerModule where

    ind = Set

  not = Set  -- fails

    again-indented = Set

My opinion: Also in the top level module, if you start indented, you need to
continue indented. There should not be a special treatment of the top module
other than you can omit the indentation altogether.

Original issue reported on code.google.com by andreas....@gmail.com on 8 Dec 2014 at 2:34

@GoogleCodeExporter
Copy link
Author

Doesn't seem to be special treatment of the top module, rather it seems to be
special treatment of zero indentation.

Like you say, this is okay:

module m where
 a = Set
b = Set

and it's only when it becomes

module m where
 a = Set
b = Set
 c = Set

that a parse error occurs. However, this fails:

module m where
  a = Set
 b = Set

Original comment by Whee...@gmail.com on 24 Apr 2015 at 2:10

@GoogleCodeExporter GoogleCodeExporter added type: bug Issues and pull requests about actual bugs auto-migrated modules Issues relating to the module system parser Problems with the parser's implementation (rather than with decisions about syntax) labels Aug 8, 2015
@GoogleCodeExporter
Copy link
Author

GoogleCodeExporter commented Aug 8, 2015

But in your first example, only 'a' is part of 'm', 'b' is in the top-level module, which also contains 'm'. And if 'm' is the top-level module, you have the bug I am complaining about.

Original comment by andreas....@gmail.com on 24 Apr 2015 at 3:12

@andreasabel
Copy link
Member

Issue rediscovered by a user in
https://lists.chalmers.se/pipermail/agda/2016/008463.html

@andreasabel
Copy link
Member

andreasabel commented Feb 1, 2016

It seems that the weird behavior is introduced by the following code in Parser.y:

-- | Insert a top-level module if there is none.
figureOutTopLevelModule :: [Declaration] -> [Declaration]
figureOutTopLevelModule ds =
  case span isAllowedBeforeModule ds of
    (ds0, Module r m tel ds1 : ds2) -> ds0 ++ [Module r m tel $ ds1 ++ ds2]
    (ds0, ds1)                      -> ds0 ++ [Module (getRange ds1) (QName noName_) [] ds1]

case 1: If there are no non-import statements before the first module, we add the declarations ds2 following the first module to the first module declarations ds1. This makes code like

module File where
  ds1
ds2

legal when it really should be a parse error. In general, either ds1 or ds2 should be empty for this to be legal.

@andreasabel
Copy link
Member

Issue was introduced by f304322 which fixed #953.

@asr asr added this to the 2.4.4 milestone Feb 1, 2016
andreasabel added a commit that referenced this issue Feb 1, 2016
@andreasabel andreasabel added regression on master Unreleased regression in development version (Change to "regression in ..." should it be released!) and removed auto-migrated labels Feb 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
modules Issues relating to the module system parser Problems with the parser's implementation (rather than with decisions about syntax) regression on master Unreleased regression in development version (Change to "regression in ..." should it be released!) type: bug Issues and pull requests about actual bugs
Projects
None yet
Development

No branches or pull requests

3 participants