From 006e0e0830871d2743b495013c521b72992d0efa Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Wed, 10 Apr 2019 13:16:23 -0400 Subject: [PATCH] fixed struct pattern field ordering --- src/Convert/Struct.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index 8445b95..ed304c5 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -6,8 +6,8 @@ module Convert.Struct (convert) where -import Data.Maybe (isJust) -import Data.List (sortOn) +import Data.Maybe (fromJust, isJust) +import Data.List (elemIndex, sortOn) import Data.Tuple (swap) import Control.Monad.Writer import qualified Data.Map.Strict as Map @@ -229,8 +229,9 @@ convertAsgn structs types (lhs, expr) = then zip (map (Just. snd) fields) (map snd items) else items items'' = map subMap items' - fieldRange = \(Just x, _) -> lookupUnstructRange structTf x - exprs = map snd $ reverse $ sortOn fieldRange items'' + fieldNames = map snd fields + itemPosition = \(Just x, _) -> fromJust $ elemIndex x fieldNames + exprs = map snd $ sortOn itemPosition items'' convertExpr _ other = other -- try expression conversion by looking at the *innermost* type first