Expected: 'assigned', but found: 'unassigned' when trying to execute action

‘Add Contact’ is an action within >‘Number’?‘No’. It requires some input to execute the action. Why do I get the error above when trying to call it?

Model ‘model’

/home/coder/project/models/model/application.alan:12038:33 to 12038:35 error: no valid ‘assigned variable’ found for ‘head’. Unexpected ‘variable’:

  • expected: ‘assigned’ at /home/coder/project/models/model/application.alan:12038:33 to 12038:35

  • but found: ‘unassigned’ at :1:1 to 1:1

/home/coder/project/models/model/application.alan notice: 1 semantic errors, with 100 unknown

failed to compile: compiler failed

		'CRM': stategroup = switch >'Number'.'CRM' (
				|'Yes' => 'Yes' ( )
				|'No'  as $'no' => 'No' ( )
			) (
				'Yes' { }
				'No' {
					'Add Contact': action {
						'Relation Exists': stategroup @default: 'Yes' (
							'No' {
								'Type': stategroup @default: 'Company' (
									'Person' { }
									'Company' {
										'Official Company Name': text
									}
								)
								'Default Language': text -> ^ ^ ^ ^ ^ .'Relationship Management'.'Languages'[]
							}
							'Yes' {
								'Relation': text -> ^ ^ ^ ^ ^ .'Relationship Management'.'Relations'[]
								'Contact Exists': stategroup @default: 'Yes' (
									'Yes' {
										'Contact': text -> ^ >'Relation'.'Contacts'[]
									}
									'No' { }
								)
							}
						)
					} as $'contact' => execute $^ $'no'.'Add Contact' (
						'Relation Exists' = switch $'contact'.'Relation Exists' (
							|'No'  as $ => create 'No' (
								'Type' = switch $ .'Type' (
									|'Person'  => create 'Person' ( )
									|'Company' as $ => create 'Company' (
										'Occifical Company Name' = $ .'Official Company Name'
									)
								)
								'Default Language' = $ .'Default Language'
							)
							|'Yes' as $ => create 'Yes' (
								'Relation' = $ .'Relation'
								'Contact Exists' = switch $ .'Contact Exists' (
									|'Yes' as $ => create 'Yes' (
										'Contact' = $ .'Contact'
									)
									|'No'  => create 'No' ( )
								)
							)
						)
					)

You can use $ assignments only within the scope of the (sub)expression where they are defined. For using the value of $'no' in context of the No state, you can use a where rule:

'CRM': stategroup = switch >'Number'.'CRM' (
	|'Yes' => 'Yes' ( )
	|'No'  as $'no' => /*$'no' can only be used within the scope of this | case */ 'No' where 'No' = $'no' ( )
) (
	'Yes' { }
	'No' where 'No' -> >'Number'.'CRM'?'No' { 
		// you can use the where rule in an expression with .&'No'
	}
)
1 Like