@@ -470,7 +470,7 @@ func (env *environment) EvalASTCase(n *ast.Node) (interface{}, error) {
470470 // Determine the lookup key based on test type
471471 var lookupKey int64
472472 testType := caseNode .TestType .(lang.Keyword )
473-
473+
474474 switch testType {
475475 case lang .KWInt :
476476 // For integer test type, use the value directly
@@ -493,7 +493,7 @@ func (env *environment) EvalASTCase(n *ast.Node) (interface{}, error) {
493493 if caseNode .Mask != 0 {
494494 lookupKey = int64 (uint32 (lookupKey >> uint (caseNode .Shift )) & uint32 (caseNode .Mask ))
495495 }
496-
496+
497497 case lang .KWHashIdentity :
498498 // Use identity hash for keywords
499499 hash := lang .IdentityHash (testVal )
@@ -503,7 +503,7 @@ func (env *environment) EvalASTCase(n *ast.Node) (interface{}, error) {
503503 } else {
504504 lookupKey = int64 (uint32 (hash >> uint (caseNode .Shift )) & uint32 (caseNode .Mask ))
505505 }
506-
506+
507507 case lang .KWHashEquiv :
508508 // Use hash for general values
509509 hash := lang .Hash (testVal )
@@ -513,7 +513,7 @@ func (env *environment) EvalASTCase(n *ast.Node) (interface{}, error) {
513513 } else {
514514 lookupKey = int64 (uint32 (hash >> uint (caseNode .Shift )) & uint32 (caseNode .Mask ))
515515 }
516-
516+
517517 default :
518518 return nil , fmt .Errorf ("unknown test type: %v" , testType )
519519 }
@@ -522,7 +522,7 @@ func (env *environment) EvalASTCase(n *ast.Node) (interface{}, error) {
522522 // Following Clojure's implementation: find the entry whose key matches lookupKey
523523 // If that entry is marked as collision, evaluate result directly (it's a condp)
524524 // Otherwise, verify the test value matches before evaluating result
525-
525+
526526 for _ , entry := range caseNode .Entries {
527527 if entry .Key != lookupKey {
528528 continue
@@ -538,54 +538,54 @@ func (env *environment) EvalASTCase(n *ast.Node) (interface{}, error) {
538538 } else {
539539 // Non-collision case, need to verify the actual value matches
540540 if testType == lang .KWInt {
541- // For integers with shift/mask, we need to verify the actual value
542- // because multiple values can map to the same key
543- if caseNode .Mask != 0 {
544- // Need to check actual value matches
545- expectedVal , err := env .EvalAST (entry .TestConstant )
546- if err != nil {
547- return nil , err
548- }
549- if lang .Equals (testVal , expectedVal ) {
550- result , err := env .EvalAST (entry .ResultExpr )
551- if err != nil {
552- return nil , err
553- }
554- return result , nil
555- }
556- } else {
557- // For integers without shift/mask, the key match is sufficient
541+ // For integers with shift/mask, we need to verify the actual value
542+ // because multiple values can map to the same key
543+ if caseNode .Mask != 0 {
544+ // Need to check actual value matches
545+ expectedVal , err := env .EvalAST (entry .TestConstant )
546+ if err != nil {
547+ return nil , err
548+ }
549+ if lang .Equals (testVal , expectedVal ) {
558550 result , err := env .EvalAST (entry .ResultExpr )
559551 if err != nil {
560552 return nil , err
561553 }
562554 return result , nil
563555 }
564556 } else {
565- // For hash-based dispatch, verify the actual value matches
566- expectedVal , err := env .EvalAST (entry .TestConstant )
557+ // For integers without shift/mask, the key match is sufficient
558+ result , err := env .EvalAST (entry .ResultExpr )
567559 if err != nil {
568560 return nil , err
569561 }
570-
571- // Use appropriate comparison based on test type
572- var matches bool
573- if testType == lang .KWHashIdentity {
574- matches = testVal == expectedVal
575- } else {
576- matches = lang .Equals (testVal , expectedVal )
562+ return result , nil
563+ }
564+ } else {
565+ // For hash-based dispatch, verify the actual value matches
566+ expectedVal , err := env .EvalAST (entry .TestConstant )
567+ if err != nil {
568+ return nil , err
569+ }
570+
571+ // Use appropriate comparison based on test type
572+ var matches bool
573+ if testType == lang .KWHashIdentity {
574+ matches = testVal == expectedVal
575+ } else {
576+ matches = lang .Equals (testVal , expectedVal )
577+ }
578+ if matches {
579+ result , err := env .EvalAST (entry .ResultExpr )
580+ if err != nil {
581+ return nil , err
577582 }
578- if matches {
579- result , err := env .EvalAST (entry .ResultExpr )
580- if err != nil {
581- return nil , err
582- }
583- return result , nil
583+ return result , nil
584584 }
585585 }
586586 }
587587 }
588-
588+
589589 // No match found, evaluate default
590590 return env .EvalAST (caseNode .Default )
591591}
0 commit comments