Fl4m3Ph03n1x

Fl4m3Ph03n1x

Cannot understand warnings in Gradient

Background

I am now trying Gradual type checking, as a consequence I am giving a shot to Gradient. As I see it, this is an alternative to Dialyzer.

Problems

So, on my first ever code snippet, I started with a pure function:

defmodule TipCalculator do

  @spec getTipPercentage(List[String.t()]) :: non_neg_integer
  def getTipPercentage(names) do
    names_size = length(names)

    cond do
      names_size > 5 -> 20
      names_size > 0 -> 10
      true -> 0
    end
  end
end

From my point of view, my type checks are rather solid.
However, Gradient seems to have a different opinion:

===> Analyzing applications...
===> Compiling gradualizer
src/gradualizer.erl:45:2: Warning: opaque type top() is underspecified and therefore meaningless

src/typechecker.erl:3234:1: Warning: function type_check_cons_in/4 is unused
src/typechecker.erl:3247:1: Warning: function type_check_cons_union/4 is unused
src/typechecker.erl:4612:1: Warning: function verbose/3 is unused
src/typechecker.erl:4870:1: Warning: function gen_partition/3 is unused
src/typechecker.erl:4872:1: Warning: function paux/3 is unused

==> gradient
Compiling 14 files (.ex)
Generated gradient app
==> grokking_fp
Compiling 1 file (.ex)
warning: code block contains unused literal "\n" (remove the literal or assign it to _ to avoid warnings)
  lib/tip_calculator.ex: TipCalculator

Generated grokking_fp app
Typechecking files...
lib/tip_calculator.ex: Undefined remote type Access:get/2 on line 0

From what I can understand, this one piece of code (from a fresh project) has several issues:

  1. warning: code block contains unused literal “\n” (remove the literal or assign it to _ to avoid warnings)
  2. lib/tip_calculator.ex: Undefined remote type Access:get/2 on line 0

The fist one sounds like a warning credo (or a linter) would give me. So I am not really sure what do do with it. I am expecting a tool that does type checks only (maybe I am wrong?).

The second one, I have no idea.

Questions

What am I doing wrong?

Marked As Solved

Fl4m3Ph03n1x

Fl4m3Ph03n1x

Answer

I got confused a little bit, the correct typing was [String.t] and not List[String.t].

I will say however that:

lib/tip_calculator.ex: Undefined remote type Access:get/2 on line 0

Is not (to me) a very descriptive error message.
However, given the alternative (dialzyer) message is not much better:

lib/tip_calculator.ex:8:unknown_type
Unknown type: Access.get/2.

I will say however, the line number was an incredible help to find the issue.
With Gradient line 0 really threw me off.

Also Liked

OvermindDL1

OvermindDL1

The first thing about the warning looks like just a warning in the gradient’s source, not yours.

The second thing is because Access.get is how elixir desugars things like what looks like array accesses, so typing @spec getTipPercentage(List[String.t()]) :: non_neg_integer is actually typing @spec getTipPercentage(Access.get(List, String.t())) :: non_neg_integer, which doesn’t make much sense as a type. ^.^;

But yeah, that’s not an issue for erlang code, it’s just some of Elixir’s magic making the type error a bit weird.

Where Next?

Popular Backend topics Top

ohm
Does anybody have good learning resources with regards to going into Event Driven Design, Architecture or Sourcing? I got recommended Er...
New
Fl4m3Ph03n1x
Background I am now trying Gradual type checking, as a consequence I am giving a shot to Gradient. As I see it, this is an alternative to...
New
JimmyCarterSon
I am confused about the Schema setup, I am setting up a new application and I want to seed files in it as well. I tried to mix to create...
New
AstonJ
If when trying to create (or recreate) your dev db with rails db:create you are getting: PG::ConnectionBad: connection to server on soc...
New
sona11
I’m having a difficulty. I want to modify an attribute’s data type from String to Array. { “id”: “trn:tarb:tradingpartner:uuid:00000...
New
Sumityadav
Hello all, I am new to learning Java Programming and want to learn java from scratch. I was writing a Java program to get the first and l...
New
pillaiindu
What is the difference between using :references and :belongs_to in the following command? bin/rails generate scaffold LineItem product:...
New
jaeyson
Hi! I have clarifications (please correct me, as I mostly mix/confuse this details) with the following: The term RAG here where it read...
New
Patricia-Mendes13
Hi guys!! I´m studying and got a Full stack course but the course lacked a lot of support and and info to learn as it´s a course after wo...
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New

Other popular topics Top

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
AstonJ
Seems like a lot of people caught it - just wondered whether any of you did? As far as I know I didn’t, but it wouldn’t surprise me if I...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
New
husaindevelop
Inside our android webview app, we are trying to paste the copied content from another app eg (notes) using navigator.clipboard.readtext ...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
CommunityNews
A Brief Review of the Minisforum V3 AMD Tablet. Update: I have created an awesome-minisforum-v3 GitHub repository to list information fo...
New
AstonJ
This is cool! DEEPSEEK-V3 ON M4 MAC: BLAZING FAST INFERENCE ON APPLE SILICON We just witnessed something incredible: the largest open-s...
New