# Homomorphic Encryption example compilation error

**URL:** <https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706>\
**Category:** Related Projects\
**Created:** [August 5, 2024, 3:10pm UTC](https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706 "2024-08-05T15:10:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![finestructure](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finestructure/32/34879_2.png) [@finestructure](https://forums.swift.org/u/finestructure)\
**Post date:** [August 5, 2024, 3:10pm UTC](https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706/1 "2024-08-05T15:10:38Z")

</div>

I'm trying to run the [Using Homomorphic Encryption example](https://www.swift.org/blog/announcing-swift-homomorphic-encryption/#using-homomorphic-encryption) from the announcement blog post in a playground and am running into an `Ambiguous use of 'decrypt(using:)'` error on the line

```swift
let decrypted = try ciphertext.decrypt(using: secretKey)

```

as well as a (possible downstream) error `Cannot infer contextual base in reference to member 'coefficient'` on the line just below:

```swift
let decoded: [UInt64] = try decrypted.decode(format: .coefficient)

```

I'm guessing the example is missing some qualification on the `decrypt` call's return type but I can't quite figure out what I'd put there to help the compiler. It's not `Bfv<UInt64>.CoeffPlaintext` by the looks of it.

Am I missing something obvious or is the example out of date perhaps?

 ![CleanShot 2024-08-05 at 17.10.09@2x](https://global.discourse-cdn.com/swift/original/3X/7/3/735cc57b7711fdb2d619fe26b9a8a305b8b6567d.png)

---

<div class="post-metadata">

**Author:** ![Quedlinbug](https://avatars.discourse-cdn.com/v4/letter/q/77aa72/32.png) [@Quedlinbug](https://forums.swift.org/u/Quedlinbug)\
**Post date:** [August 5, 2024, 8:33pm UTC](https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706/2 "2024-08-05T20:33:32Z")

</div>

> [@finestructure](#):
>
> It's not `Bfv<UInt64>.CoeffPlaintext` by the looks of it.

It is!

The example works fine for me, but not in a playground, where I see what you do.

I haven't gotten a playground to work for several years, and consider them abandoned.

---

<div class="post-metadata">

**Author:** ![finestructure](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finestructure/32/34879_2.png) [@finestructure](https://forums.swift.org/u/finestructure)\
**Post date:** [August 5, 2024, 8:54pm UTC](https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706/3 "2024-08-05T20:54:51Z")

</div>

Mmm, neither

```swift
let decrypted: Bfv<UInt64>.CoeffPlaintext = try ciphertext.decrypt(using: secretKey)

```

nor

```swift
let decrypted = try ciphertext.decrypt(using: secretKey) as Bfv<UInt64>.CoeffPlaintext

```

help to resolve the ambiguity. Is there another way to force the correct overload that I could try?

I'll try sticking it in a test as well, this was just the easiest way to try this. (And it usually works quite reliably, I do this routinely for packages I'm trying out).

Thanks for taking a look!

---

<div class="post-metadata">

**Author:** ![Quedlinbug](https://avatars.discourse-cdn.com/v4/letter/q/77aa72/32.png) [@Quedlinbug](https://forums.swift.org/u/Quedlinbug)\
**Post date:** [August 5, 2024, 10:40pm UTC](https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706/4 "2024-08-05T22:40:19Z")

</div>

> [@finestructure](#):
>
> I do this routinely for packages I'm trying out

I've heard you talk about it on the podcast (of which I am a regular listener—thanks for doing it!), and wish I had as good of a general experience with them as you do. I really liked playgrounds from 2014 to about 2018, used them daily, and wish they would be considered as worthy of support as they seemed to be back then.

---

<div class="post-metadata">

**Author:** ![fboemer](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/fboemer/32/36420_2.png) [@fboemer](https://forums.swift.org/u/fboemer)\
**Post date:** [August 5, 2024, 11:08pm UTC](https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706/5 "2024-08-05T23:08:10Z")

</div>

We have made a few API changes to resolve the ambiguous references, but that hasn't been tagged in a release yet. Can you try depending on

```swift
.package(
    url: "https://github.com/apple/swift-homomorphic-encryption",
    branch: "main"),

```

?

For reference, the blog post example is similar to this snippet: [swift-homomorphic-encryption/Snippets/HomomorphicEncryption/BasicsSnippet.swift at 780e3215cb48a5c681286d8f41d8a982bc313ccf · apple/swift-homomorphic-encryption · GitHub](https://github.com/apple/swift-homomorphic-encryption/blob/780e3215cb48a5c681286d8f41d8a982bc313ccf/Snippets/HomomorphicEncryption/BasicsSnippet.swift), which can be run with `swift run BasicsSnippet`.

---

<div class="post-metadata">

**Author:** ![finestructure](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finestructure/32/34879_2.png) [@finestructure](https://forums.swift.org/u/finestructure)\
**Post date:** [August 6, 2024, 6:44am UTC](https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706/6 "2024-08-06T06:44:53Z")

</div>

The snippet does indeed compile and run in my playground based off of `main`. Thanks a lot for the pointer, @fboemer !

---

<div class="post-metadata">

**Author:** ![finestructure](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/finestructure/32/34879_2.png) [@finestructure](https://forums.swift.org/u/finestructure)\
**Post date:** [August 6, 2024, 6:53am UTC](https://forums.swift.org/t/homomorphic-encryption-example-compilation-error/73706/7 "2024-08-06T06:53:20Z")

</div>

I love to hear that someone's listening in on our ramblings, thank you 🙂

I suspect part of it is that I've learned to step around the problems with playgrounds over the years. There's always the ritual of closing and reopening them when dependencies aren't building as well as trimming down code but on the whole I'm still able to get quite far with playgrounds.

One of the main things I do to make them more stable is move chunks of code into files in `Sources`. It gives better compiler errors (sometimes it's the _only_ way to get compiler errors) and it'll run much faster.
