Skip to content

Panic with local definiton that uses constraint guards without a type signature #1685

@RyanGlScott

Description

@RyanGlScott

If you give this Cryptol this program:

module Bug where

f : ()
f = g
  where
    g | 0 == 0 => ()

Then Cryptol will panic:

$ ~/Software/cryptol-3.1.0/bin/cryptol Bug.cry 
┏━╸┏━┓╻ ╻┏━┓╺┳╸┏━┓╻  
┃  ┣┳┛┗┳┛┣━┛ ┃ ┃ ┃┃  
┗━╸╹┗╸ ╹ ╹   ╹ ┗━┛┗━╸
version 3.1.0
https://cryptol.net  :? for help

Loading module Cryptol
Loading module Bug
cryptol: You have encountered a bug in Cryptol's implementation.
*** Please create an issue at https://github.com/GaloisInc/cryptol/issues

%< --------------------------------------------------- 
  Revision:  65397a491bddc3b4e8f41053106ce8859387d662
  Branch:    release-3.1.0 (uncommited files present)
  Location:  [TypeCheck] checkMonoB
  Message:   Used constraint guards without a signature at 
             (at Bug.cry:6:5--6:6, g)
CallStack (from HasCallStack):
  panic, called at src/Cryptol/Utils/Panic.hs:21:9 in cryptol-3.1.0-inplace:Cryptol.Utils.Panic
  panic, called at src/Cryptol/TypeCheck/Infer.hs:1622:17 in cryptol-3.1.0-inplace:Cryptol.TypeCheck.Infer
%< ---------------------------------------------------

Note that making slight changes to the program will change the panic to a proper Cryptol error message:

  • If you give g a type signature:

    module Bug where
    
    f : ()
    f = g
      where
        g : ()
        g | 0 == 0 => ()
    

    Then Cryptol will error thusly:

    $ ~/Software/cryptol-3.1.0/bin/cryptol Bug.cry 
    ┏━╸┏━┓╻ ╻┏━┓╺┳╸┏━┓╻  
    ┃  ┣┳┛┗┳┛┣━┛ ┃ ┃ ┃┃  
    ┗━╸╹┗╸ ╹ ╹   ╹ ┗━┛┗━╸
    version 3.1.0
    https://cryptol.net  :? for help
    
    Loading module Cryptol
    Loading module Bug
    [error] at Bug.cry:7:5--7:6:
      Local declaration `g` may not use constraint guards.
      Constraint guards may only appear at the top-level of a module.
    
  • If you use constraint guards at the top level without a type signature, as in this program:

    module Bug where
    
    f | 0 == 0 => ()
    

    Then Cryptol will error thusly:

    $ ~/Software/cryptol-3.1.0/bin/cryptol Bug.cry 
    ┏━╸┏━┓╻ ╻┏━┓╺┳╸┏━┓╻  
    ┃  ┣┳┛┗┳┛┣━┛ ┃ ┃ ┃┃  
    ┗━╸╹┗╸ ╹ ╹   ╹ ┗━┛┗━╸
    version 3.1.0
    https://cryptol.net  :? for help
    
    Loading module Cryptol
    Loading module Bug
    At Bug.cry:3:1--3:2: Declarations using constraint guards require an explicit type signature.
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething not working correctlytype-guards

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions