skiptools / skiptools/skip

`.environment(\.font, .custom(...))` type inference fails with a confusing error message

Open
#347 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Swift
Stars
3.2k
Forks
106
Avg merge
6d 13h
Merged PRs (30d)
1

Description

In SwiftUI, you can use the .environment() modifier to set a custom default font, like this:

.environment(\.font, .custom("Protest Guerrilla", size: 30.0))

But Skip has a type inference bug in this code: you have to call it with Font.custom() and not with simply .custom(), or it will fail to compile on Android.

I know that type-inference bugs are something I just have to deal with in Skip, but instead of saying, "Cannot infer type for this parameter", I get a really cryptic error message.

To reproduce this bug, I forked the Showcase app https://github.com/dfabulich/skipapp-showcase/tree/environment-font-bug-example and added a one-line commit: https://github.com/dfabulich/skipapp-showcase/commit/4d55295eeccc98e66e33a313b59d27ace864779c

Expected: Build fails with "Cannot infer type for this parameter" error

Actual:

Argument type mismatch: actual type is 'kotlin.Function1<ERROR CLASS: Unknown return lambda parameter type, ERROR CLASS: Unknown return lambda parameter type>', but 'kotlin.String' was expected.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Showcase app branch and its one-line commit reproducing the .environment(\.font, .custom(...)) call. Compare the expected type-inference diagnostic with the actual Kotlin error during the Android build; done means the failure reports "Cannot infer type for this parameter" instead of the cryptic type mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, swift
Domain
compilers, mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.