Skip to content

pattern matching on conditional expression #325

Open
@lutzhamel

Description

@lutzhamel

Code like this

function member
   with ([],_) do
     false
   with ([h|_],m) when h==m do  <<<< illegal
     true
   with ([_|t],m) do
     member(t,m)
end

Should generate an error. The illegal pattern gets mapped into a pattern with apply nodes in it,

  |  |  |  |  |  |  |  |(lineinfo 
  |  |  |  |  |  |  |  |  |(member1.ast 4)) 
  |  |  |  |  |  |  |  |(body 
  |  |  |  |  |  |  |  |  |(body-pattern 
  |  |  |  |  |  |  |  |  |  |(apply 
  |  |  |  |  |  |  |  |  |  |  |(id __eq__) 
  |  |  |  |  |  |  |  |  |  |  |(tuple 
  |  |  |  |  |  |  |  |  |  |  |  |[ 
  |  |  |  |  |  |  |  |  |  |  |  |  |(apply       <<<<
  |  |  |  |  |  |  |  |  |  |  |  |  |  |(apply 
  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |(tuple 
  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |[ 
  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |(head-tail 
  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |(id h) 
  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |(id _)) 
  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |(id m)]) 
  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |(id when))    <<<<
  |  |  |  |  |  |  |  |  |  |  |  |  |  |(id h)) 
  |  |  |  |  |  |  |  |  |  |  |  |  |(id m)]))) 
  |  |  |  |  |  |  |  |  |(stmt-list 
  |  |  |  |  |  |  |  |  |  |(list 
  |  |  |  |  |  |  |  |  |  |  |[ 
  |  |  |  |  |  |  |  |  |  |  |  |(lineinfo 
  |  |  |  |  |  |  |  |  |  |  |  |  |(member1.ast 5)) 
  |  |  |  |  |  |  |  |  |  |  |  |(clear-ret-val) 
  |  |  |  |  |  |  |  |  |  |  |  |(exp-stmt 
  |  |  |  |  |  |  |  |  |  |  |  |  |(set-ret-val 
  |  |  |  |  |  |  |  |  |  |  |  |  |  |(boolean True)))]))) 

This needs to be rejected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions