Skip to content

convertAssignAny doesn't work for json([...]) Variables #344

@sdemjanenko

Description

@sdemjanenko

I have found that sol.Scan doesn't serialize JSON Variables. The issue seems to come from the convertAssignAny method's case engine.Compound branch.

When I add this logging

if err := iter.Err(); err != nil {
  fmt.Println("convertAssignAny compound iteration err", err)
  return errConversion
}

I get this output

convertAssignAny compound iteration err error(type_error(list,json([=(id,someid),=(message,foobar)])),put_char/2)

Here is an example that hits this error

results(ResultJSON) :-
  ...
  ResultJSON = json([
    id = ResultID,
    message = Message
  ]).
type Solution struct {
  Result any `prolog:"ResultJSON"`
}
// Also fails with
// type Solution struct {
//   Result struct {
//     ID string `json:"id"`
//     Message string `json:"message"`
//   } `prolog:"ResultJSON"`
// }

sols, err := p.Query(`results(ResultJSON).`)
...
for sols.Next() {
  var s Solution
  if err := sols.Scan(&s); err != nil {
     ...
  }
  ...
}

The Go code returns this error failed to run prolog eval: conversion failed from sols.Scan(&s)

Is there a way to get this Scan working? Or does does the library code need to change internally to support this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions