bblfsh / sdk

Babelfish driver SDK
GNU General Public License v3.0
23 stars 27 forks source link

Roles are sorted in encoding step but not in decoding one #431

Open ncordon opened 5 years ago

ncordon commented 5 years ago

A node with roles like:

Visibility, World, Declaration, Type

would be encoded as:

Declaration, Type, Visibility, World

due to this line which is code called by libuast. We should probably move the sorting to after the transformations step (as suggested by @creachadair and @dennwc) to avoid having decoding and encodings (when we parse a tree and we just decode it for example, then if we encode and decode back we end up with different orders).

Reproducible example, using scala-client:

import org.bblfsh.client.v2.BblfshClient, BblfshClient._

// This file is in scala-client repo
val fileName = "src/test/resources/Tiny.java"
val fileContent = Source.fromFile(fileName).getLines.mkString("\n")
val resp = client.parse(fileName, fileContent)
val ctx: ContextExt = resp.uast.decode()
val tree = ctx.root()
val bytes = ctx.encode(tree, fmt)
val decoded = BblfshClient.decode(bytes, fmt)