{"action":"created","comment":{"url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/comments/35000681","id":35000681,"diff_hunk":"@@ -231,28 +252,67 @@ case class WorkflowActor(workflow: WorkflowDescriptor,\n     }\n \n     def lookup(identifierString: String): WdlValue = {\n-      /* Start by assuming the identifierString is a Namespace reference, and if it is return that reference.\n-       * Otherwise, assume it's referencing a Call and return the value of that call as a WdlObject,\n-       * which represents the outputs of the Call (WdlObject only returned if outputs are present)\n+      /* This algorithm defines three ways to lookup an identifier in order of their precedence:\n+       *\n+       *   1) Look for a WdlNamespace with matching name\n+       *   2) Look for a Call with a matching name (perhaps using a scope resolution algorithm)\n+       *   3) Look for a Declaration with a matching name (perhaps using a scope resolution algorithm)\n+       *\n+       * Each method is tried individually and the first to return a Success value takes precedence.\n        */\n \n-      val namespaces = workflow.namespace.namespaces filter {_.importedAs.contains(identifierString)}\n-      namespaces.headOption.getOrElse {\n-        val matchedCall = parentWorkflow.calls.find {_.name == identifierString}.getOrElse {\n-          throw new WdlExpressionException(s\"Expecting to find a call with name '$identifierString'\")\n+      def lookupNamespace(name: String): Try[WdlNamespace] = {\n+        workflow.namespace.namespaces.find {_.importedAs.contains(name)} match {\n+          case Some(x) => Success(x)\n+          case _ => Failure(new WdlExpressionException(s\"Could not resolve $identifierString as a namespace\"))\n         }\n-        val futureValue = fetchCallOutputEntries(matchedCall).map { entries =>\n-          val callOutputs = entries.map { entry =>\n-            val value = entry.wdlValue match {\n-              case Some(v) => v\n-              case _ => throw new WdlExpressionException(s\"Could not evaluate call '${matchedCall.name}', because '${entry.key.name}' is undefined\")\n+      }\n+\n+      def lookupCall(name: String): Try[WdlObject] = {\n+        parentWorkflow.calls.find {_.name == identifierString} match {\n+          case Some(matchedCall) =>\n+            val futureValue = fetchCallOutputEntries(matchedCall).map {callOutputEntries =>\n+              val callOutputsAsMap = callOutputEntries.map { entry =>\n+                entry.key.name -> entry.wdlValue\n+              }.toMap\n+              callOutputsAsMap.find {case (k,v) => v.isEmpty} match {\n+                case Some(noneValue) => Failure(new WdlExpressionException(s\"Could not evaluate call ${matchedCall.name} because some if its inputs are not defined (i.e. $noneValue._1\"))\n+                case None => Success(WdlObject(callOutputsAsMap.map {case (k,v) => k -> v.get}))\n+              }\n             }\n-            entry.key.name -> value\n-          }\n-          WdlObject(callOutputs.toMap)\n+            Await.result(futureValue, DatabaseTimeout)\n+          case None => Failure(new WdlExpressionException(s\"Could not find a call with name '$identifierString'\"))\n         }\n-        Await.result(futureValue, DatabaseTimeout)\n       }\n+\n+      def lookupDeclaration(name: String): Try[WdlValue] = {\n+        parentWorkflow.declarations.find {_.name == identifierString} match {\n+          case Some(declaration) =>\n+            val futureValue = fetchFullyQualifiedName(declaration.fullyQualifiedName).map {\n+              case t: Traversable[SymbolStoreEntry] if t.isEmpty =>\n+                Failure(new WdlExpressionException(s\"Could not find a declaration with name '$identifierString'\"))\n+              case t: Traversable[SymbolStoreEntry] if t.size > 1 =>\n+                Failure(new WdlExpressionException(s\"Expected only one declaration for '$identifierString', got ${t.size}\"))\n+              case t: Traversable[SymbolStoreEntry] => t.head.wdlValue match {","path":"src/main/scala/cromwell/engine/workflow/WorkflowActor.scala","position":103,"original_position":103,"commit_id":"5b959bea14dc0d6e523d0cf1975160aaa150ada9","original_commit_id":"5b959bea14dc0d6e523d0cf1975160aaa150ada9","user":{"login":"geoffjentry","id":961771,"avatar_url":"https://avatars.githubusercontent.com/u/961771?v=3","gravatar_id":"","url":"https://api.github.com/users/geoffjentry","html_url":"https://github.com/geoffjentry","followers_url":"https://api.github.com/users/geoffjentry/followers","following_url":"https://api.github.com/users/geoffjentry/following{/other_user}","gists_url":"https://api.github.com/users/geoffjentry/gists{/gist_id}","starred_url":"https://api.github.com/users/geoffjentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoffjentry/subscriptions","organizations_url":"https://api.github.com/users/geoffjentry/orgs","repos_url":"https://api.github.com/users/geoffjentry/repos","events_url":"https://api.github.com/users/geoffjentry/events{/privacy}","received_events_url":"https://api.github.com/users/geoffjentry/received_events","type":"User","site_admin":false},"body":"map/getOrElse","created_at":"2015-07-20T14:35:10Z","updated_at":"2015-07-20T14:35:10Z","html_url":"https://github.com/broadinstitute/cromwell/pull/100#discussion_r35000681","pull_request_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/100","_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/comments/35000681"},"html":{"href":"https://github.com/broadinstitute/cromwell/pull/100#discussion_r35000681"},"pull_request":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/100"}}},"pull_request":{"url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/100","id":40348524,"html_url":"https://github.com/broadinstitute/cromwell/pull/100","diff_url":"https://github.com/broadinstitute/cromwell/pull/100.diff","patch_url":"https://github.com/broadinstitute/cromwell/pull/100.patch","issue_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/100","number":100,"state":"open","locked":false,"title":"Declarations","user":{"login":"scottfrazer","id":58551,"avatar_url":"https://avatars.githubusercontent.com/u/58551?v=3","gravatar_id":"","url":"https://api.github.com/users/scottfrazer","html_url":"https://github.com/scottfrazer","followers_url":"https://api.github.com/users/scottfrazer/followers","following_url":"https://api.github.com/users/scottfrazer/following{/other_user}","gists_url":"https://api.github.com/users/scottfrazer/gists{/gist_id}","starred_url":"https://api.github.com/users/scottfrazer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottfrazer/subscriptions","organizations_url":"https://api.github.com/users/scottfrazer/orgs","repos_url":"https://api.github.com/users/scottfrazer/repos","events_url":"https://api.github.com/users/scottfrazer/events{/privacy}","received_events_url":"https://api.github.com/users/scottfrazer/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-20T12:53:54Z","updated_at":"2015-07-20T14:35:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5f87e8946a02a6b9cbfc99de1bbf6f1ccca1d884","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/100/commits","review_comments_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/100/comments","review_comment_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls/comments{/number}","comments_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/100/comments","statuses_url":"https://api.github.com/repos/broadinstitute/cromwell/statuses/5b959bea14dc0d6e523d0cf1975160aaa150ada9","head":{"label":"broadinstitute:declarations","ref":"declarations","sha":"5b959bea14dc0d6e523d0cf1975160aaa150ada9","user":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"repo":{"id":34136406,"name":"cromwell","full_name":"broadinstitute/cromwell","owner":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/broadinstitute/cromwell","description":"Workflow Execution Engine using WDL","fork":false,"url":"https://api.github.com/repos/broadinstitute/cromwell","forks_url":"https://api.github.com/repos/broadinstitute/cromwell/forks","keys_url":"https://api.github.com/repos/broadinstitute/cromwell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/cromwell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/cromwell/teams","hooks_url":"https://api.github.com/repos/broadinstitute/cromwell/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/cromwell/events","assignees_url":"https://api.github.com/repos/broadinstitute/cromwell/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/cromwell/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/cromwell/tags","blobs_url":"https://api.github.com/repos/broadinstitute/cromwell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/cromwell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/cromwell/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/cromwell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/cromwell/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/cromwell/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/cromwell/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/cromwell/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/cromwell/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/cromwell/subscription","commits_url":"https://api.github.com/repos/broadinstitute/cromwell/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/cromwell/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/cromwell/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/cromwell/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/cromwell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/cromwell/merges","archive_url":"https://api.github.com/repos/broadinstitute/cromwell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/cromwell/downloads","issues_url":"https://api.github.com/repos/broadinstitute/cromwell/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/cromwell/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/cromwell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/cromwell/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/cromwell/releases{/id}","created_at":"2015-04-17T19:39:36Z","updated_at":"2015-07-11T15:11:20Z","pushed_at":"2015-07-20T13:58:49Z","git_url":"git://github.com/broadinstitute/cromwell.git","ssh_url":"git@github.com:broadinstitute/cromwell.git","clone_url":"https://github.com/broadinstitute/cromwell.git","svn_url":"https://github.com/broadinstitute/cromwell","homepage":"http://broadinstitute.github.io/cromwell/","size":3803,"stargazers_count":5,"watchers_count":5,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":5,"default_branch":"master"}},"base":{"label":"broadinstitute:develop","ref":"develop","sha":"b3c64b878415ea93c1771b64fd96ae2964a8a60f","user":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"repo":{"id":34136406,"name":"cromwell","full_name":"broadinstitute/cromwell","owner":{"login":"broadinstitute","id":393552,"avatar_url":"https://avatars.githubusercontent.com/u/393552?v=3","gravatar_id":"","url":"https://api.github.com/users/broadinstitute","html_url":"https://github.com/broadinstitute","followers_url":"https://api.github.com/users/broadinstitute/followers","following_url":"https://api.github.com/users/broadinstitute/following{/other_user}","gists_url":"https://api.github.com/users/broadinstitute/gists{/gist_id}","starred_url":"https://api.github.com/users/broadinstitute/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/broadinstitute/subscriptions","organizations_url":"https://api.github.com/users/broadinstitute/orgs","repos_url":"https://api.github.com/users/broadinstitute/repos","events_url":"https://api.github.com/users/broadinstitute/events{/privacy}","received_events_url":"https://api.github.com/users/broadinstitute/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/broadinstitute/cromwell","description":"Workflow Execution Engine using WDL","fork":false,"url":"https://api.github.com/repos/broadinstitute/cromwell","forks_url":"https://api.github.com/repos/broadinstitute/cromwell/forks","keys_url":"https://api.github.com/repos/broadinstitute/cromwell/keys{/key_id}","collaborators_url":"https://api.github.com/repos/broadinstitute/cromwell/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/broadinstitute/cromwell/teams","hooks_url":"https://api.github.com/repos/broadinstitute/cromwell/hooks","issue_events_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/events{/number}","events_url":"https://api.github.com/repos/broadinstitute/cromwell/events","assignees_url":"https://api.github.com/repos/broadinstitute/cromwell/assignees{/user}","branches_url":"https://api.github.com/repos/broadinstitute/cromwell/branches{/branch}","tags_url":"https://api.github.com/repos/broadinstitute/cromwell/tags","blobs_url":"https://api.github.com/repos/broadinstitute/cromwell/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/broadinstitute/cromwell/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/broadinstitute/cromwell/git/refs{/sha}","trees_url":"https://api.github.com/repos/broadinstitute/cromwell/git/trees{/sha}","statuses_url":"https://api.github.com/repos/broadinstitute/cromwell/statuses/{sha}","languages_url":"https://api.github.com/repos/broadinstitute/cromwell/languages","stargazers_url":"https://api.github.com/repos/broadinstitute/cromwell/stargazers","contributors_url":"https://api.github.com/repos/broadinstitute/cromwell/contributors","subscribers_url":"https://api.github.com/repos/broadinstitute/cromwell/subscribers","subscription_url":"https://api.github.com/repos/broadinstitute/cromwell/subscription","commits_url":"https://api.github.com/repos/broadinstitute/cromwell/commits{/sha}","git_commits_url":"https://api.github.com/repos/broadinstitute/cromwell/git/commits{/sha}","comments_url":"https://api.github.com/repos/broadinstitute/cromwell/comments{/number}","issue_comment_url":"https://api.github.com/repos/broadinstitute/cromwell/issues/comments{/number}","contents_url":"https://api.github.com/repos/broadinstitute/cromwell/contents/{+path}","compare_url":"https://api.github.com/repos/broadinstitute/cromwell/compare/{base}...{head}","merges_url":"https://api.github.com/repos/broadinstitute/cromwell/merges","archive_url":"https://api.github.com/repos/broadinstitute/cromwell/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/broadinstitute/cromwell/downloads","issues_url":"https://api.github.com/repos/broadinstitute/cromwell/issues{/number}","pulls_url":"https://api.github.com/repos/broadinstitute/cromwell/pulls{/number}","milestones_url":"https://api.github.com/repos/broadinstitute/cromwell/milestones{/number}","notifications_url":"https://api.github.com/repos/broadinstitute/cromwell/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/broadinstitute/cromwell/labels{/name}","releases_url":"https://api.github.com/repos/broadinstitute/cromwell/releases{/id}","created_at":"2015-04-17T19:39:36Z","updated_at":"2015-07-11T15:11:20Z","pushed_at":"2015-07-20T13:58:49Z","git_url":"git://github.com/broadinstitute/cromwell.git","ssh_url":"git@github.com:broadinstitute/cromwell.git","clone_url":"https://github.com/broadinstitute/cromwell.git","svn_url":"https://github.com/broadinstitute/cromwell","homepage":"http://broadinstitute.github.io/cromwell/","size":3803,"stargazers_count":5,"watchers_count":5,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/100"},"html":{"href":"https://github.com/broadinstitute/cromwell/pull/100"},"issue":{"href":"https://api.github.com/repos/broadinstitute/cromwell/issues/100"},"comments":{"href":"https://api.github.com/repos/broadinstitute/cromwell/issues/100/comments"},"review_comments":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/100/comments"},"review_comment":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/broadinstitute/cromwell/pulls/100/commits"},"statuses":{"href":"https://api.github.com/repos/broadinstitute/cromwell/statuses/5b959bea14dc0d6e523d0cf1975160aaa150ada9"}}}}